Forum Discussion

Jacky_2022's avatar
Jacky_2022
New Member
3 years ago
Solved

Average calculation of two specific comparative values

Hi all, I am an absolute rookie in Power BI and I don't know what to do with the following case.   I want to calculate the average value from two month-over-month change values. But the comparativ...
  • v-yueyunzh-msft's avatar
    3 years ago

    Hi , Jacky_2022 

     According to your description, you want to calculate the "Average calculation of two specific comparative values". And the date is this:

    Comparative value 1: July 2021 to July 2020

    Comparative value 2: July 2022 to July 2021

    Here are the steps you can refer to :
    (1)This is my test data:

    (2)We can create a  calendar date table like this:

    Calendar = ADDCOLUMNS(
    CALENDAR(FIRSTDATE('Table'[Date]),LASTDATE('Table'[Date]))
    ,"year_month" , YEAR([Date])*100+MONTH([Date]))
    

    And make relationship to our table like this:

    (3)Then we can create a measure like this:

    Measure = var _202107_value = CALCULATE( SUM('Table'[Value]) ,  FILTER( ALL('Calendar') , 'Calendar'[year_month] = 202107))
    var _202007_value = CALCULATE( SUM('Table'[Value]) ,  FILTER( ALL('Calendar') , 'Calendar'[year_month] = 202007))
    var _202207_value = CALCULATE( SUM('Table'[Value]) ,  FILTER( ALL('Calendar') , 'Calendar'[year_month] = 202207))
    return
    DIVIDE((_202107_value -_202007_value)+(_202207_value-_202107_value),2)

    (4)Then we can put this measure on the visual and we can meet your need , the result is as follows:

     

    If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

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