Forum Discussion

Cipriano's avatar
Cipriano
Helper III
4 years ago
Solved

Recursive calculation in table using DAX

Good afternoon everyone,   To request your support, I am starting in Power BI, and I need to perform the calculation of the column: consumptionCalculated, this value is calculated:   1.- When the...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Cipriano ,

     

    Please try this code to create a calcualted column.

    consumoCalculado = 
    VAR _Child =
        SUMMARIZE (
            FILTER (
                'Table',
                'Table'[nombre] <> EARLIER ( 'Table'[nombre] )
                    && CONTAINSSTRING ( 'Table'[nombre], EARLIER ( 'Table'[nombre] ) )
            ),
            [nombre]
        )
    VAR _SUMCHILD =
        CALCULATE (
            SUM ( 'Table'[consumo] ),
            FILTER ( 'Table', 'Table'[nombre] IN _Child )
        )
    RETURN
        IF ( 'Table'[consumo] <> BLANK (), 'Table'[consumo], _SUMCHILD )

    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.