Forum Discussion

Art666's avatar
Art666
Frequent Visitor
2 years ago

DAX Cumulative Total incremented by this total

Hi, Has anyone a idea how to solve this situation in DAX.

In Excel it is quite easy becasue you can always refer to a specific cell.

 

I need to increment the A Value by B Value, and if A is Blank the A increment should happen by the previous result of the calculation.

 

 

Thank You in advance!

3 Replies

  • I have my data setup like so (actually the 550 in the data isn't used at all, i just need the starting values for A and B and the number of rows to go up to... and the row and the starting values don't even need to be in the same table):

    And then a measure:

    Sum of A = 
    var firstAValue = CALCULATE(MIN(Cumulative[A]), Cumulative[Row] = 0)
    var firstBValue = CALCULATE(MIN(Cumulative[B]), Cumulative[Row] = 0)
    var currentRow = SELECTEDVALUE(Cumulative[Row])
    var result = firstAValue * IF(currentRow = 0, 1, currentRow) + (firstBValue * (IF(currentRow = 0, 1, currentRow) - 1))
    RETURN result

    which you can adapt to get the value for B

    • Art666's avatar
      Art666
      Frequent Visitor

      Hi vicky_

      Thank you for your help.

       

      However it is still not working:

       

       

      Any idea why this could fail?

       

      PS. I made the same calculation on hard pasted data and it seems to work.

      Above a have a summarisecolumn table.

       

       

  • I have my data setup like so (actually the 550 in the data isn't used at all, i just need the starting values for A and B and the number of rows to go up to... and the row and the starting values don't even need to be in the same table):

    And then a measure:

    Sum of A = 
    var firstAValue = CALCULATE(MIN(Cumulative[A]), Cumulative[Row] = 0)
    var firstBValue = CALCULATE(MIN(Cumulative[B]), Cumulative[Row] = 0)
    var currentRow = SELECTEDVALUE(Cumulative[Row])
    var result = firstAValue * IF(currentRow = 0, 1, currentRow) + (firstBValue * (IF(currentRow = 0, 1, currentRow) - 1))
    RETURN result

    which you can adapt to get the value for B