Forum Discussion

maddaelle's avatar
maddaelle
Frequent Visitor
3 years ago
Solved

Need help with my code - incremental calculated column DAX

Hi everyone,  I need help fixing my code for an incremental column based on 2 conditions.   Here it is:   It is not working properly because you can see in row 16 I don't want to be shown ...
  • Anonymous's avatar
    Anonymous
    3 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 Zhou

     

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