Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi, It doesn't seem like measure is showing the correct average at the grand total row. I have a table with 3 rows
the measure calculates each row in the table correctly however it doesn't calculate the average of the 3 rows. It calculates the average of unsummarized level. However the table visual is showing a summarized level and I would like it to calculate the average correctly regardless which level.
Order Number | Var | Average of Var |
o3892 | 1 | 100% |
o3792 | 1 | 100% |
o2739 | 0 | 0% |
total | not summarized | 90.91%, should show 66.67% |
it is showing 90.91% because its calculating the average on 11 rows at the granular level. But the table is a roll up view.
This was my measure
Average of Var = CALCULATE(AVERAGE(Table1 [Var] ))
Solved! Go to Solution.
Hi,
I don't think what you looking to do is possible "directly".
It's a fundamentally different calculation as one is calculating an average for each order and then averaging them together. The other is a straight average.
You can deal with lots of stuff at different levels of hierachy using ISINSCOPE/ISFILTERED type tests however none of that helps you when you get to the total row because on the total row none of the columns you're interested in exist in the FILTER context.
The only way round I can think of doing it is having a disconnected table with two values in a grain column: "Order Grain" and "Item Grain"
You can then drop that into the visual level filter and use the following measure:
Avg at Correct Grain =
VAR OrderGrain =
AVERAGEX(
VALUES ( Table1[OrderNum] ),
CALCULATE ( AVERAGE ( Table1[Var] ) )
)
VAR ItemGrain =
AVERAGE ( Table1[Var] )
VAR SelectedGrain = SELECTEDVALUE ( GrainSelector[Grain] )
RETURN
IF (
SelectedGrain = "Order Grain",
OrderGrain,
ItemGrain
)
(Note my demo data is different from yours)
Personally I'd normally just have two different measures for each grain.
If someone has a more elegant solution I'd be interested but based on my understanding of filter contexts I don't think there is one.
You can use an IF statement use HASONEFILTER to identify what grain you're working at:
https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376
OrderNum | var | Average Var % |
O93834 | 1 | 100% |
O37824 | 0 | 0% |
O37924 | 0 | 0% |
O52828 | 1 | 100% |
Total | 57% |
should show 50% at grand total
OrderNum | Item# | Var | Average Var % |
O93834 | 13/3242 | 1 | 100% |
O93834 | 13/3784 | 1 | 100% |
O93834 | 11/1374 | 1 | 100% |
O52828 | 33/3820 | 1 | 100% |
O37924 | 34/4729 | 0 | 0% |
O37924 | 12/3729 | 0 | 0% |
O37824 | 11/5748 | 0 | 0% |
Total | 57% |
@bcdobbs , I hope this helps to explain. I want the Average Var% measure to work regardless of ordernumber or itemnumber. what is shown in the visua should be calculated
Hi,
I don't think what you looking to do is possible "directly".
It's a fundamentally different calculation as one is calculating an average for each order and then averaging them together. The other is a straight average.
You can deal with lots of stuff at different levels of hierachy using ISINSCOPE/ISFILTERED type tests however none of that helps you when you get to the total row because on the total row none of the columns you're interested in exist in the FILTER context.
The only way round I can think of doing it is having a disconnected table with two values in a grain column: "Order Grain" and "Item Grain"
You can then drop that into the visual level filter and use the following measure:
Avg at Correct Grain =
VAR OrderGrain =
AVERAGEX(
VALUES ( Table1[OrderNum] ),
CALCULATE ( AVERAGE ( Table1[Var] ) )
)
VAR ItemGrain =
AVERAGE ( Table1[Var] )
VAR SelectedGrain = SELECTEDVALUE ( GrainSelector[Grain] )
RETURN
IF (
SelectedGrain = "Order Grain",
OrderGrain,
ItemGrain
)
(Note my demo data is different from yours)
Personally I'd normally just have two different measures for each grain.
If someone has a more elegant solution I'd be interested but based on my understanding of filter contexts I don't think there is one.
@bcdobbs Thanks, This works but I would like the measure to work regardless of the column. So at the granular level if I choose to see the Average of var by Items it should work it out correctly and if I choose to see by OrderNumber which is parent in the Hierachy it should calculate correctly as well.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
111 | |
100 | |
80 | |
64 | |
58 |
User | Count |
---|---|
148 | |
111 | |
93 | |
84 | |
66 |