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
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
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.

Top Solution Authors