Forum Discussion

Analitika's avatar
Analitika
Post Prodigy
4 years ago

How to calculate difference between different rows and columns in the same table in Power BI?

Hello,

 

I am trying to calculate the difference between values which are in different rows and columns. When I am trying to calculate I am getting a wrong result. Seems my query calculates difference by values in same row.

Here is my data table example:

My expected result is:

My output result is:

 

Seems that result is wrong. I expected to 0.87 but I am  getting -3289,13. So what's wrong here in my DAX fomula?

My query is here:

Column =
VAR _0 = MINX(FILTER('DBA view_DidknObj','DBA view_DidknObj'[DID_DAT]> EARLIER('DBA view_DidknObj'[DID_DAT]) && 'DBA view_DidknObj'[SAS_KOD]= EARLIER('DBA view_DidknObj'[SAS_KOD])),[DID_DAT])
VAR _1 = MAXX(FILTER('DBA view_DidknObj','DBA view_DidknObj'[DID_DAT] =_0 && 'DBA view_DidknObj'[SAS_KOD]= EARLIER('DBA view_DidknObj'[SAS_KOD]) ),[SUM_CRE])
return
if('DBA view_DidknObj'[SAS_KOD] <> 0,_1 - 'DBA view_DidknObj'[SUM_DEB], blank())

 

5 Replies

  • Analitika , Try these

     

    Calc 1 =
    var _1 = maxx(FILTER('Table', [ID] =EARLIER('Table'[ID]) && [CRE]<>0) ,[CRE])
    return if([DET] <>0, _1 -[DET])

    or


    Calc 12 =
    var _1 = maxx(FILTER('Table', [ID] =EARLIER('Table'[ID]) && [CRE]<>0 && [DATE] >EARLIER('Table'[DATE]) ) ,[CRE])
    return if([DET] <>0, _1 -[DET])

    • Analitika's avatar
      Analitika
      Post Prodigy

      amitchandak Yes I have tried but is possible to include filter Id like id=500 because there are more rows in data? In the same query I mean.

    • Analitika's avatar
      Analitika
      Post Prodigy

      Hello having error

      Calc 1 =
      var _1 = maxx(FILTER('DBA view_DidknObj', [SAS_KOD] =EARLIER('DBA view_DidknObj'[SAS_KOD]) && [SUM_CRE]<>0) ,[SUM_CRE] && FILTER('DBA view_DidknObj','DBA view_DidknObj'[id] in {20210}))
      return if([SUM_DEB] <>0, _1 -[SUM_DEB]) 

       

       

  • V-lianl-msft's avatar
    V-lianl-msft
    Community Support

    Unfortunately, I don't know your calculation logic. The fields in your formula are inconsistent with the sample data you provided, so it's difficult to correctly express what you mean. Please provide a pbix file after deleting sensitive data and the calculation logic you want to implement.

  • Best regards

    How you could get the different values from the columns in such an array.

    The idea is that I should compare prices between the different production batches and paint red the row that has at least a different price.