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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
webportal
Impactful Individual
Impactful Individual

Sum the value of one column based on the maximum value of another column

I need a measure to add the last non blank value from column SaldoConta from the table pcsabelow from each column conta.

 

The criteria to define last non blank is the one with maximum value in column AnoMes.

 

Capturar.PNG

 

I've tried a million different DAX expressions but it seems impossible to get what I want.

 

It should add only the LAST nonblank value in AnoMes, so for conta 110, it should be 112,56.

1 ACCEPTED SOLUTION

Hi @webportal,

 

You could create a formula below to group the max Anomes and Conta.

 

 

t =
ADDCOLUMNS (
    SUMMARIZE ( 'table', [Conta], "maxAnomes", MAX ( 'table'[Anomes] ) ),
    "maxSaldoConta", LOOKUPVALUE (
        'table'[SaldoConta],
        'table'[Conta], [Conta],
        [Anomes], [maxAnomes]
    )
)

 

Then you could create the measure to calculate the sum of [maxSaldoConta].

 

Here is the output.

 

Capture.PNG

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
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
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @webportal,

 

You could have a try with the formula below.

 

 

Measure =
IF (
    LASTNONBLANK ( 'Table'[Anomes], 1 ),
    CALCULATE (
        MAX ( 'Table'[SaldoConta] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Conta] = MAX ( 'Table'[Conta] )
                && 'Table'[Anomes] = MAX ( 'Table'[Anomes] )
        )
    )
)

Here is the output.

 

 

Capture.PNG

If I miss something, please share your desired output, so that we can help further investigate on it?

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-piga-msft thank you for helping!

The issue here is I don't have a filter context for "conta" and I need to sum the values of "SaldoConta" of the rows that correspond to the maximum "AnoMes" of each 'conta' - which can be different for each "conta".

Hi @webportal,

 

You could create a formula below to group the max Anomes and Conta.

 

 

t =
ADDCOLUMNS (
    SUMMARIZE ( 'table', [Conta], "maxAnomes", MAX ( 'table'[Anomes] ) ),
    "maxSaldoConta", LOOKUPVALUE (
        'table'[SaldoConta],
        'table'[Conta], [Conta],
        [Anomes], [maxAnomes]
    )
)

 

Then you could create the measure to calculate the sum of [maxSaldoConta].

 

Here is the output.

 

Capture.PNG

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.