Forum Discussion
Aggregate by more than one column with added filter
- 8 years ago
HI v-xjiin-msft,
Thank you for trying to help me. I was finally able to resolve my issue as specified below but can you please help optimize the same ?
Basically, my problem was that I have 3 filters with a group by on two of them.
I was having a hard time making the Group By filters work with the 3rd filter while computing average.
The problem occurs when I try to print to print the average at the row level.
Grouping by : Model Group and Print Mode
Another filter is : Month/Year
I was able to resolve this using this using the below DAX measure.
AvgValue= AVERAGEX(ALLSELECTED(TestData),CALCULATE(AVERAGE([Print count]),GROUPBY(TestData,TestData[Model Group],TestData[Print Mode])))
Any help in ptimizing would be very helpful.
- 8 years ago
Hi ar_46,
I'm glad to hear that you have resolved your issue. And your solution is great.
Then here's another method to get the average value without using GROUPBY(). It is hard to say which one is better, you can just make a reference.
AvgValue without GroupBy = CALCULATE ( AVERAGE ( TestData[Print Count] ), FILTER ( ALLSELECTED ( TestData ), TestData[Model Group] = MAX ( TestData[Model Group] ) && TestData[Print Mode] = MAX ( TestData[Print Mode] ) ) )Thanks,
Xi Jin.
Hi ar_46,
Could you please share us your pbix file with One Drive or Google Drive if possible? It'll help us understand your requirement more clearly.
Thanks,
Xi Jin.
HI v-xjiin-msft,
Thank you for trying to help me. I was finally able to resolve my issue as specified below but can you please help optimize the same ?
Basically, my problem was that I have 3 filters with a group by on two of them.
I was having a hard time making the Group By filters work with the 3rd filter while computing average.
The problem occurs when I try to print to print the average at the row level.
Grouping by : Model Group and Print Mode
Another filter is : Month/Year
I was able to resolve this using this using the below DAX measure.
AvgValue= AVERAGEX(ALLSELECTED(TestData),CALCULATE(AVERAGE([Print count]),GROUPBY(TestData,TestData[Model Group],TestData[Print Mode])))
Any help in ptimizing would be very helpful.
- v-xjiin-msft8 years ago
Solution Sage
Hi ar_46,
I'm glad to hear that you have resolved your issue. And your solution is great.
Then here's another method to get the average value without using GROUPBY(). It is hard to say which one is better, you can just make a reference.
AvgValue without GroupBy = CALCULATE ( AVERAGE ( TestData[Print Count] ), FILTER ( ALLSELECTED ( TestData ), TestData[Model Group] = MAX ( TestData[Model Group] ) && TestData[Print Mode] = MAX ( TestData[Print Mode] ) ) )Thanks,
Xi Jin.