Forum Discussion

DanCasSan's avatar
DanCasSan
Icon for Helper V rankHelper V
6 years ago
Solved

Perform an average per month and class

Dear, I am trying to calculate the average amount for "n" years and months, as shown in the image attached. However, I have not found any right way to do it. Any advice or trick you can give me?   ...
  • v-alq-msft's avatar
    6 years ago

    Hi, DanCasSan 

     

    Based on your description, I created data to reproduce your scenario.

    Table:

    Calendar:

    Calendar = CALENDARAUTO()

     

    There is a one-to-many relationship between two tables. I create a 'Month-Year' column in 'Calendar' table.

    Month-Year = 
    IF(
        MONTH('Calendar'[Date])<10,
        YEAR('Calendar'[Date])&"0"&MONTH('Calendar'[Date]),
        YEAR('Calendar'[Date])&MONTH('Calendar'[Date])
    
    )

     

    You may create a measure as follows.

    Average = 
    IF(
        ISFILTERED('Calendar'[Month-Year]),
        BLANK(),
        DIVIDE(
            CALCULATE(
                SUM('Table'[Value]),
                ALL('Calendar'[Month-Year])
            ),
            CALCULATE(
                DISTINCTCOUNT('Calendar'[Month-Year]),
                ALLSELECTED('Calendar')
            )    
        )
    )

     

    Result:

    If I misunderstand your thoughts, please show us your expected result and sample data. Do mask sensitive data before uploading. Thanks

     

    Best Regards

    Allan

     

    If this post helps, then please consider Accept it as the solution to help the other members to find it more quickly.