Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Average calculation

Hi all, I need to do average monthly calculation in pbi There was some problem with my dax, which is not giving correct average I am doing count(matter_key)  after that I am doing cumulative ...
  • jdbuchanan71's avatar
    2 years ago

    Anonymous 

    I rewrote it to use a couple measures.

    1. Just the count of records.

     

    Matter Key Count = COUNT( 'WL Matter Extract'[MATTER_KEY] )

     

    2. A YTD running total of that count

     

    Cummulative Count = 
    CALCULATE ( [Matter Key Count], DATESYTD ( 'Calendar Date'[Date] ) )

     

    3. A YTD active months count.  Only count months that have records in the 'WL Matter Extract' table

     

    Cummulative Month Count = 
    CALCULATE (
        COUNTROWS (
            CALCULATETABLE (
                VALUES ( 'Calendar Date'[Month Year] ),
                'WL Matter Extract'
            )
        ),
        DATESYTD ( 'Calendar Date'[Date] )
    )

     

    The Avg measure, where I only show the amount on months that have records to keep it from rolling forward to all future moths in the year.

     

    Avg = 
    VAR _Count = [Matter Key Count]
    VAR _YTDCount = [Cummulative Count]
    VAR _Months = [Cummulative Month Count]
    RETURN DIVIDE ( _Count, _Count ) * DIVIDE ( _YTDCount, _Months )

     

     

    I have attached my sample file for you to look at.