Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Return max row count

Hi All, 

 

I have a table like the following: 

 

MonthCost CentrePay Period Number 

1/7/21

XX11
1/7/21XX12
1/7/21XX13

1/8/21

 XX14

1/8/21

 XX15

1/9/21

 XX16

 

I want to create either a measure  that basically counts the rows based on month and summarises the date by month.

 

i.e. for example, for Cost Centre XX1 in the month of 1/7/21, there are 3 pay periods so i want it to return 3. 

For 1/8/21, there are 2 pay periods, so i want to be able to return 2.

 

Does anyone know how i can do this? 

 

thank you!

 

 

  •  

    expected 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] )
    )
    RETURN
    IF ( HASONEVALUE ( 'Table'[Month] ), DIVIDE ( amounttotal, maxperiodnumber ) )

10 Replies

  • Hi, 

    I am not sure if I understood your question correctly, but please check the below picture and the measure.

     

     

    Row Count Measure: =
    COUNTROWS('Table' )
     
    • Anonymous's avatar
      Anonymous
      Not 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

      MonthCost CentrePeriod NumberAmount
      1/7/21 15
      1/7/21 234
      1/7/21 32
      • AllisonKennedy's avatar
        AllisonKennedy
        Community Champion

        Anonymous You can use AVERAGEX for this:

         

        AVERAGEX(VALUES(DimDate[Month]), [Measure])