Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Cipriano
Helper III
Helper III

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 father does not have a value in the column: consumption and its value is dependent on the consumption of its children. For example:

 

consumoCalculado de PadreA = consumo Hijo1dePadreA + consumo Hijo2dePadreB

consumoCalculado de PadreA = 200 + 300

consumoCalculado de PadreA = 500

 

2.- When the parent or children have a value in the column: consumption,

 

consumoCalculado de PadreC = consumo

consumoCalculado de PadreC = 100

 

consumoCalculado de Hijo1dePadreB = consumo

consumoCalculado de Hijo1dePadreB = 100

 

La tabla de datos de ejemplo:

 

clavePadreclavenombreconsumoinventariosaldoconsumoCalculado
 cve001PadreA 1000800500
 cve004PadreB   200
 cve007PadreC100600500100
cve001cve002Hijo1dePadreA200  200
cve001cvd003Hijo2dePadreA300  300
cve004cve005Hijo1dePadreB100200100100
cve004cve006Hijo2dePadreB100300200100

 

In advance, I thank you for your valuable support.

Greetings, Cipriano.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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.

RicoZhou_0-1661249074551.png

 

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.

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

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.

RicoZhou_0-1661249074551.png

 

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.

 

I really appreciate your support, regards.

lbendlin
Super User
Super User

Will you have situations in your data where PadreC does not have any child records?

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.