Forum Discussion

jdoshi65's avatar
jdoshi65
Frequent Visitor
9 years ago
Solved

Dynamic calculate Measure value based on Slicer Selection

Hi Floks,

 

I have one requirement, where I want to calculate measures based on the user slicer selection. I have sused below formula to create measure to display average of previous month.

 

Avg of Prev Month = AVERAGE('System Data'[ResponseTime]) - CALCULATE(AVERAGE('System Data'[ResponseTime]), PREVIOUSMONTH('System Data'[Date].[Date]))

 

For Slicer, I have used Hierarchy Slicer and displaying Year -> Quarter -> Month.

 

I want to display Average of selection slicer value, if user selects Year then it will calculate Avg of Prev Year, if user selects Quarter then calculate Avg of Prev Quarter and if user selects month then measure should calculate average of prev month.

 

It seems not feasible to do with single column however if there is anywork around to achieve this will be appricieated.

 

Thanks a lot in advance :)

  • I think they way you can achieve this by creating calculation for year/quarter/month and then in your final measure, you can use conditional statement:

     

    mPrevious Month = CALCULATE(Average(Sheet1[MyData]),ALL('Calendar'), PARALLELPERIOD('Calendar'[Date], -1,MONTH))
    mPrevious Year = CALCULATE(AVERAGE(Sheet1[MyData]),ALL('Calendar'), PARALLELPERIOD('Calendar'[Date], -1
    ,YEAR))

     

    mPrevious Quarter = CALCULATE(AVERAGE(Sheet1[MyData]),ALL('Calendar'), PARALLELPERIOD('Calendar'[Date]
    , -1,QUARTER))

     

     

    Now final calculation using above 3 measures:

     

    mMonth Quarter Year =
    
    AVERAGE(Sheet1[MyData]) -
    
     if(HASONEVALUE('Calendar'[Month]),[mPrevious Month],if(HASONEVALUE('Calendar'[Quarter]),[mPrevious Quarter],if(HASONEVALUE('Calendar'[Year]),[mPrevious Year],[mPrevious Month])))

    I didn't checked the syntax etc but i believe this will give you good start.

     

    Thanks,

    P

1 Reply

  • I think they way you can achieve this by creating calculation for year/quarter/month and then in your final measure, you can use conditional statement:

     

    mPrevious Month = CALCULATE(Average(Sheet1[MyData]),ALL('Calendar'), PARALLELPERIOD('Calendar'[Date], -1,MONTH))
    mPrevious Year = CALCULATE(AVERAGE(Sheet1[MyData]),ALL('Calendar'), PARALLELPERIOD('Calendar'[Date], -1
    ,YEAR))

     

    mPrevious Quarter = CALCULATE(AVERAGE(Sheet1[MyData]),ALL('Calendar'), PARALLELPERIOD('Calendar'[Date]
    , -1,QUARTER))

     

     

    Now final calculation using above 3 measures:

     

    mMonth Quarter Year =
    
    AVERAGE(Sheet1[MyData]) -
    
     if(HASONEVALUE('Calendar'[Month]),[mPrevious Month],if(HASONEVALUE('Calendar'[Quarter]),[mPrevious Quarter],if(HASONEVALUE('Calendar'[Year]),[mPrevious Year],[mPrevious Month])))

    I didn't checked the syntax etc but i believe this will give you good start.

     

    Thanks,

    P