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 ,
According to your sample, I couldn't find [Name] column. If your calculation need filter based on [Name], you may need to add name filter in each step. I think you can try ALLEXCEPT() function on table in step1.
If this reply still couldn't help you solve your issue, please show me the whole table with [Name] and show me a screenshot with the result you want. This will make me easier to find the solution.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous ,
thanks for your answer. I achieved filtering the table by adding a variable to your code = the filtered table and then using it inside the functions of your code.
Now it works fine for me.
So thank you very much for your help, I am marking it as the solution for my post.
Still, if you had some time, I would really appreciate a little explanation on how you were able to make the reasoning for my case and to solve it this way! Is there any source where I can read about this "steps" coding?
Again, thanks.