Forum Discussion

roalisco's avatar
roalisco
Frequent Visitor
1 year ago
Solved

YoY % variation based on selected year

Hi, 

I have a DAX measure called '4w_roll_avg' that calculates the 4 week rolling average. I want to create another measure that calculates the YoY % variation based on the selection of a base year. For that, I created a parameter called 'Base YoY comparison' that displays year values from 2009 onwards and added it a slicer in my report. 

So, giving this input:

Date4w_roll_avg
01/01/20181900
01/02/20181300
01/01/20191400
01/02/20191325
01/01/20231800

 

If I select 2019 as my 'Base YoY comparison' then I should get:

Date4w_roll_avgYoY%
01/01/2023180029%
01/02/2023165025%


But If I select 2018 as my 'Base YoY comparison' then I should get:

Date4w_roll_avgYoY%
01/01/20231800-5%
01/02/2023165027%


Thanks

  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi  roalisco ,

     

    Here are the steps you can follow:

    1. Create measure.

    Measure =
    var _select=[Base YoY comparison Value]
    var _table=
    SUMMARIZE(ALL('Table'),[Date],"4w_roll_avg",[4w_roll_avg])
    var _selectsum=
    SUMX(
        FILTER(_table,YEAR('Table'[Date])=_select&&MONTH('Table'[Date])=MONTH(MAX('Table'[Date]))),[4w_roll_avg])
    return
    IF(
        YEAR(MAX('Table'[Date]))>_select,
        DIVIDE(
            [4w_roll_avg]-_selectsum,_selectsum))

    2. Result:

     

     

    Best Regards,

    Liu Yang

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

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  roalisco ,

     

    Here are the steps you can follow:

    1. Create measure.

    Measure =
    var _select=[Base YoY comparison Value]
    var _table=
    SUMMARIZE(ALL('Table'),[Date],"4w_roll_avg",[4w_roll_avg])
    var _selectsum=
    SUMX(
        FILTER(_table,YEAR('Table'[Date])=_select&&MONTH('Table'[Date])=MONTH(MAX('Table'[Date]))),[4w_roll_avg])
    return
    IF(
        YEAR(MAX('Table'[Date]))>_select,
        DIVIDE(
            [4w_roll_avg]-_selectsum,_selectsum))

    2. Result:

     

     

    Best Regards,

    Liu Yang

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