Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Delta that get dates from date filter

Hello, I would like to calculate the delta for 2023 versus 2022 and for 2024 versus 2023.
Specifically if I select from the date filter, only the months January and February of both years, how do I calculate the delta for only these two months?
In a nutshell I want the date filter to command on the calculated delta measure/column.

What calculated measure/column should I write in Power BI?

Data:
Time[Year], Time[Month]
PV[Store]
SD[Sold]


 

Thank you!





  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi,Anonymous 
    I am glad tp help you.

    Based on your description, you can try my test results below

    Filtering by fields in the matrix or in the table itself makes the DAX code easy.

    Here is my DAX code.

    M_CurrentSold = 
    CALCULATE(SUM('SD'[Sold]))
    
    M_previousSold = 
    CALCULATE(SUM('SD'[Sold]),DATEADD('Time'[Date],-1,YEAR))
    
    M_result = 
    [M_CurrentSold]-[M_previousSold]
    

     

    I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

    Best Regards,

    Carson Jian,

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

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi,Anonymous 
    I am glad tp help you.

    Based on your description, you can try my test results below

    Filtering by fields in the matrix or in the table itself makes the DAX code easy.

    Here is my DAX code.

    M_CurrentSold = 
    CALCULATE(SUM('SD'[Sold]))
    
    M_previousSold = 
    CALCULATE(SUM('SD'[Sold]),DATEADD('Time'[Date],-1,YEAR))
    
    M_result = 
    [M_CurrentSold]-[M_previousSold]
    

     

    I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

    Best Regards,

    Carson Jian,

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

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks, but delta so calculated is not dynamic with changing dates on filter.

      I have this kind of filter

      If I want to display the delta between May 2024 and March 2023, for the year 2024 it will display the delta between May 2024 and May 2023, not for the range I selected in the filter (May2024 and March 2023). How can I modify the query so that the filter controls on the delta to be displayed? Thank you so much

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thank you, i reached the solution with a similar method so i accept your comment as solution!