Forum Discussion
Return max row count
- 4 years agoexpected result: =VAR amounttotal =CALCULATE (SUM ( 'Table'[Amount] ),ALLEXCEPT ( 'Table', 'Table'[Month], 'Table'[Cost Centre] ))VAR maxperiodnumber =CALCULATE (COUNTROWS('Table'),ALLEXCEPT ( 'Table', 'Table'[Month], 'Table'[Cost Centre] ))RETURNIF ( HASONEVALUE ( 'Table'[Month] ), DIVIDE ( amounttotal, maxperiodnumber ) )
Hi,
I am not sure if I understood your question correctly, but please check the below picture and the measure.
- Anonymous4 years agoNot applicable
Hi Jihwan_Kim ,
Thanks for that. I basically need to sum the values for any given month and then based on the row count, i need to divide the value to get an average.
Result will be displayed in a card.
For example, for the below, i would sum up amount (5 + 34 + 2 = 41) and then 41/max no. of pay periods which in this case is 3.
This will be displayed in a card visual and it should work dyniamcally with the dimdate slicer
Month Cost Centre Period Number Amount 1/7/21 1 5 1/7/21 2 34 1/7/21 3 2 - AllisonKennedy4 years agoCommunity Champion
Anonymous You can use AVERAGEX for this:
AVERAGEX(VALUES(DimDate[Month]), [Measure])
- Anonymous4 years agoNot applicable
Hi AllisonKennedy ,
Thanks for that! I did try that but it's not giving me the right output.
Essentially, within a month, we have varying numbers of pay periods. So for Sept, we have 3 whereas in August, we only had 2. So we capture data each pay period but i need to essentially sum up values for that month and then determine how many pay periods there were and divide by that to average it.When i use the DAX above, i'm not getting the average for some reason 😞
- Jihwan_Kim4 years agoSuper Userexpected result: =VAR amounttotal =CALCULATE (SUM ( 'Table'[Amount] ),ALLEXCEPT ( 'Table', 'Table'[Month], 'Table'[Cost Centre] ))VAR maxperiodnumber =CALCULATE (MAX ( 'Table'[Pay Period Number ]),ALLEXCEPT ( 'Table', 'Table'[Month], 'Table'[Cost Centre] ))RETURNIF ( HASONEVALUE ( 'Table'[Month] ), DIVIDE ( amounttotal, maxperiodnumber ) )
- Anonymous4 years agoNot applicable
Hi Jihwan_Kim ,
Really appreciate your help. Instead of dividing by max pay period number, i need it to be the count of periods within that month. For example, in your file, 1/08/21 average should be 42/2 (2 because in the month of august, there are 2 pay periods). Similarly, for sept, it should be 45/1 since there is only 1 pay period.
Hope that makes sense