Categories
- All Categories
- 15 Oracle Analytics Sharing Center
- 14 Oracle Analytics Lounge
- 214 Oracle Analytics News
- 42 Oracle Analytics Videos
- 15.7K Oracle Analytics Forums
- 6.1K Oracle Analytics Idea Labs
- Oracle Analytics User Groups
- 78 Oracle Analytics Trainings
- 14 Oracle Analytics Data Visualizations Challenge
- Find Partners
- For Partners
Aggregation rules, group by

Hello everyone,
This is my first post, so I hope it finds you all well and thanks in advance for any support or contribution.
I am a very beginner and on my way to creating a more "advanced" report I am facing some difficulties to achieve my goal and therefore here I am.
In my report I need to create a condition which populates a field when a specific criteria is met. Basically, I have three fields my table Manufacturer, I have three columns: a product number, a manufacturer role and manufacturer country. I created extra columns BR , PI, QC and SP based on
WHEN "Manufacturer"."Role" = 'BR' AND
"Manufacturer"."Country" = 'UK' THEN 1 ELSE 0)
Product Number | Role | Country | BR | PI | QC | SP |
P4580 | BR | FR | 0 | 0 | 0 | 0 |
P4102 | BR | UK | 1 | 0 | 0 | 0 |
P5028 | BR | ES | 0 | 0 | 0 | 0 |
P5028 | BR | HU | 0 | 0 | 0 | 0 |
P5028 | BR | MT | 0 | 0 | 0 | 0 |
P5028 | BR | PL | 0 | 0 | 0 | 0 |
P5028 | BR | UK | 1 | 0 | 0 | 0 |
P5028 | PI | ES | 0 | 0 | 0 | 0 |
P5028 | PI | HU | 0 | 0 | 0 | 0 |
P5028 | PI | MT | 0 | 0 | 0 | 0 |
P5028 | PI | PL | 0 | 0 | 0 | 0 |
P5028 | PI | UK | 0 | 1 | 0 | 0 |
P4580 | QC | FR | 0 | 0 | 0 | 0 |
P4580 | QC | UK | 0 | 0 | 1 | 0 |
P4580 | QC | US | 0 | 0 | 0 | 0 |
P4102 | QC | UK | 0 | 0 | 1 | 0 |
P5028 | QC | ES | 0 | 0 | 0 | 0 |
P5028 | QC | HU | 0 | 0 | 0 | 0 |
P5028 | QC | MT | 0 | 0 | 0 | 0 |
P5028 | QC | NZ | 0 | 0 | 0 | 0 |
P5028 | QC | UK | 0 | 0 | 1 | 0 |
P4580 | SP | FR | 0 | 0 | 0 | 0 |
P4580 | SP | UK | 0 | 0 | 0 | 1 |
P4102 | SP | UK | 0 | 0 | 0 | 1 |
P5028 | SP | NZ | 0 | 0 | 0 | 0 |
P5028 | SP | PL | 0 | 0 | 0 | 0 |
P5028 | SP | UK | 0 | 0 | 0 | 1 |
This is my first step to identify what is UK and non UK category for every 'role type' in column role. One product can have 4 different roles BR, PI, QC and SP and many country based sites and the rule is;
If UK is the only country with role BR then give me UK only
If UK is non of the countries with role BR then give me No Uk
IF UK is one of the countries in addition to any other then give me UK also.
With my basic sql skills, i would formulate the following
CASE
WHEN MIN("Manufacturer"."Role" = 'BR' AND
"Manufacturer"."Country" = 'UK') = 0
AND
WHEN MAX("Manufacturer"."Role" = 'BR' AND
"Manufacturer"."Country" = 'UK') = 0
THEN 'No UK'
WHEN MIN("Manufacturer"."Role" = 'BR' AND
"Manufacturer"."Country" = 'UK') = 1
AND
WHEN MAX("Manufacturer"."Role" = 'BR' AND
"Manufacturer"."Country" = 'UK') = 1
THEN 'UK only'
WHEN MIN("Manufacturer"."Role" = 'BR' AND
"Manufacturer"."Country" = 'UK') = 0
AND
WHEN MAX(
"Manufacturer"."Role" = 'BR' AND
"Manufacturer"."Country" = 'UK') = 1
THEN 'UK also'
ELSE 'check'
END
GROUP BY "Manufacturer"."Product"
My first problem is that... there will probably be a much easier way to do this and probably I am over complicating my life. Secondly I don't know why BI gives me errors with this and all the combinations I have tried.... I have also tried the advanced SQL group by, but get errors as well. So, I don't know what else to do. I think our table has behind by default the group by 'product number' column.
Thanks all for giving me a hand.
All the best,
Answers
-
If you are only interested in results for the UK, you can skip all of the 1/0 columns in your first step. A single column containing a much simpler CASE statement will produce what you want.
CASE
WHEN COUNT("Manufacturer"."Country" by "Manufacturer"."Role", Product Number)=1 AND "Manufacturer"."Country"='UK' THEN 'UK Only'
WHEN COUNT("Manufacturer"."Country" by "Manufacturer"."Role", Product Number)>1 AND "Manufacturer"."Country"='UK' THEN 'UK Also'
ELSE 'No UK'
END
About the error you're getting: The WHEN clauses in your case statement should not be connected by "AND". Each WHEN is an independent set of conditions, although you can combine conditions within a WHEN clause.
Hope this helps,
Jerry0 -
Hi @Jerry Casey@,
Thanks, It defo helped, that was it
I added it another condition to fulfil my requirements
WHEN COUNT("Manufacturer"."Country" by "Manufacturer"."Role", Product Number)>= 1 AND "Manufacturer"."Country" NOT IN ('UK','uk') THEN 'No UK'
Else Null
And all works now as I wanted. I also understood the way you played with the group by and the syntax.
Thanks again
0