Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Year on Year Difference

Hi @all,
Is it possible to create a measure to find variance in PowerBI like below?

 

6 Replies

  • Hi,

    What would the result be if there were more than 2 dates in the row labels?  Also, are the row labels coming from a slicer selection?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Ashish,
    Thanks for the response. Yes, the row labels are coming from the slicer and there would always be 2 dates in the row labels.

    • Ashish_Mathur's avatar
      Ashish_Mathur
      Super User

      Hi,

      Assuming you have a Calendar Table and the dates in the row labels are from th Calendar Table, try this DAX pattern

      =calculate([Total],datesbetween(Calendar[date],MAXX(allselected(Calendar),calendar[date]),MAXX(allselected(Calendar),calendar[date]))-calculate([Total],datesbetween(Calendar[date],minx(allselected(Calendar),calendar[date]),minx(allselected(Calendar),calendar[date]))

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Ashish,
        I really appreciate your solution. Unfortunately, I'm experiencing an error: "A function 'DATESBETWEEN' has been used in a True/False expression that is used as a table filter expression. This is not allowed"

        CALCULATE ( [Net Debt], DATESBETWEEN ( DimValdate[ValDate], MAXX ( ALLSELECTED ( DimValdate ), DimValdate[ValDate] ), MAXX ( ALLSELECTED ( DimValdate ), DimValdate[ValDate] ) ) - CALCULATE ( [Net Debt], DATESBETWEEN ( DimValdate[ValDate], MINX ( ALLSELECTED ( DimValdate ), DimValdate[ValDate] ), MINX ( ALLSELECTED ( DimValdate ), DimValdate[ValDate] ) ) ) )