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
ao352
Frequent Visitor

SUM values based on rank if summed figure is less than another set value

I would like to sum a range of values in Power BI based on their ranking, if they sum up to an amount below a set value.

 

For Example: 

The price of the highest ranked items are summed up, until the point whereby the Cumulative Total exceeds the Budget. The other values which do not make the cut would not be summed up, just displayed.

 

      
   Budget£123 
      
 ItemPrice (£)RankCumulative Total 
 Ginger818 
 Cake32240 
 Banana643104 
 Pie7440 
 Strawberries7750 
 Chocolate8960 
 Total104-- 
      

 

If the budget were to change, so would the Cumulative total. 

 

      
   Budget£180 
      
 ItemPrice (£)RankCumulative Total 
 Ginger818 
 Cake32240 
 Banana643104 
 Pie744178 
 Strawberries7750 
 Chocolate8960 
 Total178-- 
      
1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

@ao352 ,

 

Suppose you have another budget table and the slicer is based on budget table, you can create a measure using DAX below to calculate the cumulative sum which hasn't exceeded the threshold:

Cumlative Total = 
VAR Budget_Value = SELECTEDVALUE(Budget[Budget])
VAR Running_Total = CALCULATE(SUM('Table'[Price]), FILTER(ALL('Table'), COUNTROWS(FILTER('Table', 'Table'[Rank] >= EARLIER('Table'[Rank])))))
RETURN
IF(Running_Total <= Budget_Value, Running_Total, 0)

Capture.PNG 

 

Community Support Team _ Jimmy Tao

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
Ashish_Mathur
Super User
Super User

Hi,

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yuta-msft
Community Support
Community Support

@ao352 ,

 

Suppose you have another budget table and the slicer is based on budget table, you can create a measure using DAX below to calculate the cumulative sum which hasn't exceeded the threshold:

Cumlative Total = 
VAR Budget_Value = SELECTEDVALUE(Budget[Budget])
VAR Running_Total = CALCULATE(SUM('Table'[Price]), FILTER(ALL('Table'), COUNTROWS(FILTER('Table', 'Table'[Rank] >= EARLIER('Table'[Rank])))))
RETURN
IF(Running_Total <= Budget_Value, Running_Total, 0)

Capture.PNG 

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you! 🙂

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.