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

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.

Reply
dmitry-wbr
Frequent Visitor

Show averages in subtotals/totals instead of sum for PBI pivot table

Hello everyone!
I've been struggling with the following problem. I have a pivot table where I calculate sum of FTE for employees with months in columns and department/employee_id in rows. Instead of sums in subtotals and totals, I want to see the averages. That's what I have right now in PBI - default aggregation with sum:

dmitrywbr_1-1645027466677.png


This is my desired result. I want average aggregation for subtotals/totals across both rows and columns, while keeping sum aggregation of FTE for each employee:

dmitrywbr_0-1645027420495.png

I have tried DAX formulas with AVERAGEX, but it allows for average aggregation only across single dimension.
I will gladly appreciate any help with that one. Link for source file: https://docs.google.com/spreadsheets/d/1mWVGys7-PAUWvryvMyhyjPmmF7iSDNEE/edit?usp=sharing&ouid=10915... 

1 ACCEPTED SOLUTION

Hi @dmitry-wbr 
I think you are trying to calculate the average of the sum.
For each "Department" AVERAGE will calculate the sum of all values of all records of each employee and aggregate the total value for all employees. Then it divides this aggregated value over the total number of records. 
What you actually want is to find the average of the visible values in your matix which is the sum of these values divided by the number of these values. 
This shall not be a problem but the thing that makes it complicated is that you have another filter on the matrix column which is the Year-Month. Therefore more conditions shall apply

Measure2 =
VAR NumberOfEmployees =
    COUNTROWS ( VALUES ( '12'[Employee_ID] ) )
VAR NumberOfMonths =
    COUNTROWS ( VALUES ( 'Date'[Year-Month] ) )
VAR SumValue =
    SUM ( '12'[FTE] )
VAR Result =
    SWITCH (
        TRUE,
        HASONEVALUE ( '12'[Employee_ID] ) && HASONEVALUE ( 'Date'[Year-Month] ), SumValue,
        HASONEVALUE ( '12'[Employee_ID] ) && NOT HASONEVALUE ( 'Date'[Year-Month] ), DIVIDE ( SumValue, NumberOfMonths ),
        DIVIDE ( SumValue, NumberOfEmployees )
    )
RETURN
    Result

Please try and let me know

View solution in original post

10 REPLIES 10
tamerj1
Super User
Super User

Hi @dmitry-wbr 

you can use

IF(

ISINSCOPE (Table[Department] ),

"your average calculation",

"your sum calculation"

)

Also HASONEVALUE shall retrun averages for both subtotals ans the grand total

Hi @tamerj1 
Thanks for the advice, but it doesn't seem to work 😞

The HASONEVALUE you use it with the sub-colum (E45, M12 .....)

IF ( HASONEVALUE (column name), SUM, AVERAGE)

Can't reach the desired result unfortunately, values are not correct

dmitrywbr_0-1645080403392.png

 

This should work

Measure2 =
IF (
    HASONEVALUE ( '12'[Employee_ID] ),
    SUM ( '12'[FTE] ),
    CALCULATE ( AVERAGE ( '12'[FTE] ), ALLSELECTED () )
)

That produces the same incorrect result unfortunately 

Hi @dmitry-wbr 
I think you are trying to calculate the average of the sum.
For each "Department" AVERAGE will calculate the sum of all values of all records of each employee and aggregate the total value for all employees. Then it divides this aggregated value over the total number of records. 
What you actually want is to find the average of the visible values in your matix which is the sum of these values divided by the number of these values. 
This shall not be a problem but the thing that makes it complicated is that you have another filter on the matrix column which is the Year-Month. Therefore more conditions shall apply

Measure2 =
VAR NumberOfEmployees =
    COUNTROWS ( VALUES ( '12'[Employee_ID] ) )
VAR NumberOfMonths =
    COUNTROWS ( VALUES ( 'Date'[Year-Month] ) )
VAR SumValue =
    SUM ( '12'[FTE] )
VAR Result =
    SWITCH (
        TRUE,
        HASONEVALUE ( '12'[Employee_ID] ) && HASONEVALUE ( 'Date'[Year-Month] ), SumValue,
        HASONEVALUE ( '12'[Employee_ID] ) && NOT HASONEVALUE ( 'Date'[Year-Month] ), DIVIDE ( SumValue, NumberOfMonths ),
        DIVIDE ( SumValue, NumberOfEmployees )
    )
RETURN
    Result

Please try and let me know

Wow, that worked perfectly! Thank you a lot!

@dmitry-wbr that's great. Please let me know if you need any further help

@dmitry-wbr Just need to mention that you need to use the correct table name and column name of  "Year-Month"

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors