Forum Discussion
Need help with my code - incremental calculated column DAX
- Anonymous3 years ago
Hi maddaelle ,
Please try this code to create a calculated column.
Column 3 = VAR _Step1 = ADDCOLUMNS ( 'Table', "Step1", SWITCH ( TRUE (), 'Table'[A] = 1 && 'Table'[B] = 0, 1, 'Table'[A] = 0 && OR ( 'Table'[B] = 0, 'Table'[B] = 1 ), 0 ) ) VAR _Step2 = ADDCOLUMNS ( _Step1, "Step2", MAXX ( FILTER ( _Step1, [Index] < EARLIER ( [Index] ) && NOT ( ISBLANK ( [Step1] ) ) ), [Index] ) ) VAR _Step3 = ADDCOLUMNS ( _Step2, "Step3", VAR _VALUE = SUMX ( FILTER ( _Step2, [Index] = EARLIER ( [Step2] ) ), [Step1] ) RETURN IF ( ISBLANK ( [Step1] ), _VALUE + [Index] - [Step2], [Step1] ) ) RETURN SUMX ( FILTER ( _Step3, [Index] = EARLIER ( 'Table'[Index] ) ), [Step3] )Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi maddaelle
Can you show the expected column along with the current sample data? At present I don't understand why "Column 3" is not working. According to my understanding of the formula "if (A = 1, if (B = 1, incremental calc, 1), 0)", the curent "Column 3" in the image seems to have returned the correct results. Which values are not correct and what are the desired values?
Best Regards,
Community Support Team _ Jing
Hi, thanks for your answer, I just updated all this work in another post, if you could check.
https://community.powerbi.com/t5/Desktop/Need-help-with-my-code-incremental-calculated-column-DAX/m-p/2934003