Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Kandarp
Helper I
Helper I

Show average of column values in grand total row

Hi,

 

I will try to explain my issue by taking an example. Please refer below screenshot. I need help to implement Yellow highlighted part. 

 

Kandarp_0-1686118532574.png

 

 

 

There is a column called "Result" which is a measure by dividing Column A and Column B. 

In the Grand total row of the matrix, I want to show "Result" value as an Average. 

 

So from the above screenshot value, I want value as 3.5. But instead I am getting 4.4 because 550/125. 

 

How to achieve 3.5 as a value in "Result" grand total. 

1 ACCEPTED SOLUTION
Kandarp
Helper I
Helper I

Hi,

 

I figured out the solution in case any one needed this. This may not be optimized solution but one can optimize as per the requirement.

 

So I have created four measures basically. 

 

MeasureA =SUM('Sample'[ColumnA])

MeasureB = SUM('Sample'[ColumnB])

IntermediateMeasure = MeasureA/MeasureB



ResultMeasure = 



VAR TotalResults = SUM('Sample'[ColumnA]) / SUM('Sample'[ColumnB])
VAR DistinctCategoryCount = DISTINCTCOUNT('Sample'[Category])
RETURN
    IF(
        ISFILTERED('Sample'[Category]),
        DIVIDE(TotalResults, DistinctCategoryCount),
        AVERAGEX(VALUES('Sample'[Category]), [IntermediateMeasure ])
    )

 

Here is the screenshot of the result : 

Kandarp_0-1686210367496.png

 

View solution in original post

5 REPLIES 5
Kandarp
Helper I
Helper I

Hi,

 

I figured out the solution in case any one needed this. This may not be optimized solution but one can optimize as per the requirement.

 

So I have created four measures basically. 

 

MeasureA =SUM('Sample'[ColumnA])

MeasureB = SUM('Sample'[ColumnB])

IntermediateMeasure = MeasureA/MeasureB



ResultMeasure = 



VAR TotalResults = SUM('Sample'[ColumnA]) / SUM('Sample'[ColumnB])
VAR DistinctCategoryCount = DISTINCTCOUNT('Sample'[Category])
RETURN
    IF(
        ISFILTERED('Sample'[Category]),
        DIVIDE(TotalResults, DistinctCategoryCount),
        AVERAGEX(VALUES('Sample'[Category]), [IntermediateMeasure ])
    )

 

Here is the screenshot of the result : 

Kandarp_0-1686210367496.png

 

Kishore_KVN
Super User
Super User

Hello @Kandarp , 

Use AVERAGEX instead of AVERAGE directly to get the overall average work the same. 

Your measure looks like this:

Average = AVERAGEX('Table','Table'[A]/'Table'[B])

Output looks like this:

Kishore_KVN_0-1686119163031.png

 

If this post helps, then please consider accepting it as the solution to help other members find it more quickly. Thank You!!

 

@Kishore_KVN Thanks this is perfect solution. But It will not work if we have multiple row with same category. In my case I have mutliple rows with same category name.

For example, if we have below data : 

 

Kandarp_0-1686122305910.png

 

Then suggested solution will not work. Expected result is 4.695 but this formula shows 5.84. See below : 

 

Kandarp_1-1686122344858.png

If you have any solution on this, please suggest. Thanks in advance.

Hello @Kandarp  in that case you have to add grouping for the category.

Average = Calculate(AVERAGEX('Table',sum('Table'[A])/sum('Table'[B])),ALLEXCEPT(Table,'Table'[Category]))

 

If this post helps, then please consider accepting it as the solution to help other members find it more quickly. Thank You!!

@Kishore_KVN Unfortunately it is giving the same result : 

 

Kandarp_0-1686130330576.png

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.