Forum Discussion

rkxiii's avatar
rkxiii
Frequent Visitor
2 years ago
Solved

How to get the Percent Difference from previous data

I would like to know what formula to use to get the percentage difference from the previous data that I have (seen from the image). Thank you!

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi, rkxiii 

     

    You can try the following methods.

    Measure:

    Diff = 
    Var _Prevdate=CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),[Date]<SELECTEDVALUE('Table'[Date])))
    Var _PrevYield=CALCULATE([Yield],FILTER(ALL('Table'),[Date]=_Prevdate))
    RETURN
    IF(_PrevYield=BLANK(),BLANK(),[Yield]-_PrevYield)

    Is this the result you expected?

     

    Best Regards,

    Community Support Team _Charlotte

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

     

6 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, rkxiii 

     

    You can try the following methods.

    Measure:

    Diff = 
    Var _Prevdate=CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),[Date]<SELECTEDVALUE('Table'[Date])))
    Var _PrevYield=CALCULATE([Yield],FILTER(ALL('Table'),[Date]=_Prevdate))
    RETURN
    IF(_PrevYield=BLANK(),BLANK(),[Yield]-_PrevYield)

    Is this the result you expected?

     

    Best Regards,

    Community Support Team _Charlotte

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

     

    • rkxiii's avatar
      rkxiii
      Frequent Visitor

      Hi, Thank you very much for your help. This is the solution I am looking for. Again, Thank you very much!

       

    • rkxiii's avatar
      rkxiii
      Frequent Visitor

      Hi,
      Also could you please include the Model Name for this solution? Thank you very much for your help!

      • rkxiii's avatar
        rkxiii
        Frequent Visitor

        Its okay now. I just Filter All Except the Model Name. Thank you!

  • Hi rkxiii, Hope you are doing good!

    Please try the below DAX to create a new calculated column as per your requirement:

    Difference =
    VAR PreviousPercent =
    CALCULATE(
    MAX(TableName[Percent]),
    FILTER(
    TableName,
    TableName[IndexColumn] = EARLIER(TableName[IndexColumn]) - 1
    )
    )
    RETURN
    IF(
    ISBLANK(PreviousPercent),
    0,
    TableName[Percent] - PreviousPercent
    )

    Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

    • rkxiii's avatar
      rkxiii
      Frequent Visitor

      Hi, Thank you for your response. 

      I used the PowerBi Visual "Table" for the table used in the image, is the solution still applicable?
      Is it also possible just to add "New Measure" for the percentage? Thank you.