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
Anonymous
Not applicable

Calculate column totals and Averages in Table

Good day, I have data as per below example:

 

DateReasonEmployeeAvailable
2020/08/25LEAVE1111110
2020/08/25LEAVE2222210
2020/08/25LEAVE2222210
2020/08/25LEAVE1111110
2020/08/25OFF3333310
2020/08/26OFF111118
2020/08/26OFF222228
2020/08/26OFF111118
2020/08/26OFF222228
2020/08/26LEAVE333338
2020/08/26LEAVE444448
2020/08/27LEAVE555554
2020/08/27LEAVE666664
2020/08/27OFF222224

 


What I would like is the results as per below in a table with averages instead of Total line. 

 

DateAvailable on DateOFFLEAVETOTALAVAILABILITY
2020/08/251041550%
2020/08/26824675%
2020/08/27421375%
Average7,32,72,04,767%

 

Note I did not use a matrix, but if its possible with a matrix please let me know.

 

Thanks

The problem is the Average row and the availability rows. How can this be accomplished?

1 ACCEPTED SOLUTION

@Anonymous 

 

This is the grand total line, it does not change by the averagex() function. To get average you can just divide by the distinctcount([date]). For example the LEAVE AVG:

LEAVE AVG = 
VAR leave= 
CALCULATE( DISTINCTCOUNT('TABLE'[EMPLOYEE] ),FILTER('TABLE','TABLE'[REASON] = "LEAVE") )
RETURN
IF(HASONEFILTER('Table'[Date]),leave, leave / DISTINCTCOUNT('Table'[Date]))

 or this measure should also work:

LEAVE AVG  = CALCULATE( DISTINCTCOUNT('TABLE'[EMPLOYEE] ),FILTER('TABLE','TABLE'[REASON] = "LEAVE") ) / DISTINCTCOUNT('Table'[Date])

 

Paul Zheng _ Community Support Team
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@Anonymous , Not sure on the logic of other columns.

 

The first one looks like

averageX(summarize(Table, Table[Date],Table[Available]),[Available])

or

averageX(summarize(Table, Table[Date],"_1",max(Table[Available])),[_1])

Anonymous
Not applicable

Thank you. averageX(summarize(Table, Table[Date],Table[Available]),[Available] works for calculating the availability. But how to do each of the other columns ensuring that the average is displayed in the Average line?

 

 Available on DateOFFLEAVETOTALAVAILABILITY
2020/08/251041550%
2020/08/26824675%
2020/08/27421375%
Average7,32,72,04,767%

@Anonymous This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

 

Also, this might help:

https://community.powerbi.com/t5/Quick-Measures-Gallery/Matrix-Measure-Total-Triple-Threat-Rock-amp-Roll/m-p/411443#M150

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler I have tried researching working with average columns but I'm not sure how to apply what you have suggested. My current formula looks like this:

 

LEAVE AVG = AVERAGEX('TABLE', CALCULATE(DISTINCTCOUNT('TABLE'[EMPLOYEE] ),FILTER('TABLE','TABLE'[REASON] = "LEAVE")))
 
The Average Row does not display the averages, instead it displays the Total
Bradley_0-1600699691077.png

 

 
 
 

@Anonymous 

 

This is the grand total line, it does not change by the averagex() function. To get average you can just divide by the distinctcount([date]). For example the LEAVE AVG:

LEAVE AVG = 
VAR leave= 
CALCULATE( DISTINCTCOUNT('TABLE'[EMPLOYEE] ),FILTER('TABLE','TABLE'[REASON] = "LEAVE") )
RETURN
IF(HASONEFILTER('Table'[Date]),leave, leave / DISTINCTCOUNT('Table'[Date]))

 or this measure should also work:

LEAVE AVG  = CALCULATE( DISTINCTCOUNT('TABLE'[EMPLOYEE] ),FILTER('TABLE','TABLE'[REASON] = "LEAVE") ) / DISTINCTCOUNT('Table'[Date])

 

Paul Zheng _ Community Support Team
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.