cancel
Showing results for
Did you mean:  Helper III

## Grand total Average is not accurate

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] ))

1 ACCEPTED SOLUTION  Super User

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.

Ben Dobbs

Did I answer your question? Mark my post as a solution! This will help others on the forum!
6 REPLIES 6  Super User

Are you able to supply a demo pbix file?

Ben Dobbs

Did I answer your question? Mark my post as a solution! This will help others on the forum!  Super User

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

Ben Dobbs

Did I answer your question? Mark my post as a solution! This will help others on the forum!  Helper III
 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  Super User

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.

Ben Dobbs

Did I answer your question? Mark my post as a solution! This will help others on the forum!  Super User

You need to do something like:

``````Average of Var =
AVERAGEX(
VALUES ( Table1[Order Number] ),
CALCULATE ( AVERAGE ( Table1[Var] ) )
)``````

Ben Dobbs

Did I answer your question? Mark my post as a solution! This will help others on the forum!  Helper III

@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. Announcements #### The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.  