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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
tamim
Frequent Visitor

Calculate the sum of multiple row with a condition

Hi,

I have the following table, as you can see the Sum of distanceKM is 512.

I want o make a measure to calculate the Sum of distanceKM until its value is less than 450km.

So, I want a condition in the measure to stop calculating the Sum once it will reach 450km.

The reason is that I want to know on which row the sum will be 450km or less.

 
 

 Capture.PNG

5 REPLIES 5
Anonymous
Not applicable

To do this you have to have an order among all the distances. If you use only the distances themselves without any outer order, then you can calculate a cumulative distance in 2 ways:
1. from the smallest distance to the biggest or
2. the other way round.
You have not specified the order, so this task does not have a clear solution.

Best
D

da.PNG

 

it look similar to this in Excel 

camargos88
Community Champion
Community Champion

Hi @tamim ,

 

Try this code for measure:

 

Measure = CALCULATE(
IF(SUM('Table'[Column1]) <= 10; SUM('Table'[Column1]); BLANK());
FILTER(ALL('Table'); 'Table'[Column1] <= MAX('Table'[Column1]))
)
 
Did I answer your question? Mark my post as a solution!
Ricardo


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Hi, Thank you for your answer
But I am still gettin an error
check the underlined:
 
Measure = CALCULATE(
IF(SUM(sheet2[distanceKM]) <= 10, SUM(sheet2[distanceKM]), BLANK()),
FILTER(ALL(sheet2), sheet2[distanceKM] <= MAX(sheet2[distanceKM]))
)
camargos88
Community Champion
Community Champion

@tamim ,

 

Can you post the error ?

 

Ricardo



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.