Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

DAX comparing two periods using slicers

Hi All, 

I am struggeling to do a simple period over period comparison based on the below example. I want to use two slicers: 1) called current priod where I can select a date, and once slicer for previous period where I want to select another date to compare the amount. 

I have listed the data and the DM for reference. 

Many thanks.

 

 

 

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Anonymous ,

     

    I suggest you to create measures as below.

    Previous Period = SELECTEDVALUE(previous_dt[Date])
    Current Period = SELECTEDVALUE(Trial3[Date])
    Current Amount = IF(ISFILTERED(Trial3[Date]),CALCULATE(SUM(Trial3[Amount])))
    Previous Amount = CALCULATE(SUM(Trial3[Amount]),FILTER(ALL(Trial3),Trial3[Date] = [Previous Period]))
    Diff = [Current Amount] - [Previous Amount]

    Result is as below.

    You can also create a measure to filter previous period slicer to only show dates before current period.

    Only Show Previous = 
    IF(MAX(previous_dt[Date]) < [Current Period],1,0)

    Add this measure into visual level filter of the slicer and set it to show items when value =1.

     

    Best Regards,
    Rico Zhou

     

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

     

     

3 Replies