Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago

Power BI

Hi Community,

 

I am building a dashboard and I have a sales values against date. I am using card (new) and have shown total sales figure. I am using a reference label wherein I added previous year's sale. The card is visible as:

I also has a year wise slicer. When I click on current year tab (2024) in slicer, the reference label does not calculate any value. The slicer is given as:

and when I click on 2024, the value visible is as below:

The DAX I used to calculate "LastYear" is as "LastYear = CALCULATE('MasterBD'[Test], SAMEPERIODLASTYEAR('MasterBD'[Date]))".

I need help on this DAX and also whenever I select any particular year, I should get previous year's sale figure in reference label.

Please help

 

8 Replies

  • Uzi2019's avatar
    Uzi2019
    Community Champion

    Hi Anonymous 
    If you have continues data you can create this below formula
    Last year sales= CALCULATE(SUM(Sales), DATEADD(Calendar'(date), -1, Year))
    If you dont have continues date try this
    CALCULATE(SUM(Sales),PARALLELPERIOD(Calendar'(date), -1, Year))

     

    You should be able to get the answer by above two measures.

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Uzi2019  Thanks for your response.

    The DAX you suggested is working fine when no slicer is applied. But when I apply slicer, it is giving blank as value.

    Please note my dates are not continuous.

    Below screenshot before applying slicer:

    and below screenshot after applying the slicer:

     

    • Uzi2019's avatar
      Uzi2019
      Community Champion

      Hi Anonymous 

      Can you take your both Sales and last year sales in table visual and seperate card visual just to test is it working for othe visual or not??


      • Anonymous's avatar
        Anonymous
        Not applicable

        It is not working in that case also. I have tried different cards. The screenshots before applying slicer is:

         

        And after applying slicer is:

        Please help