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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
dniedrauer
Resolver I
Resolver I

Sum of elements

Here's my issue: I have a formula calculating a refund amount by product for over/under consumption. Idea is refund/charge for more than 10% over/under consumption: 

 

Refund/Charge = (switch(TRUE(),[Consumption Qty]<[Allocation -10%],[Allocation-Consumption]-[Allocation]*.10,[Consumption Qty]>[Allocation +10%],[Allocation-Consumption]+[Allocation]*.10,0))*[Net Price]

 

The formula works just fine by chemical: 

Output

Chemical 1 (3940) 

Chemical 2 250 

Chemical 3 (45) etc 

 

The problem is, I need a total too. Total given is $7, but total of refund/charge for each chemical (adding each line item) is 10,319. 

7 REPLIES 7
Greg_Deckler
Community Champion
Community Champion

Assuming you are using this in something like a table/matrix and that this is a measure, you often have to change how this is calculated in the context of ALL. Typically do this with an IF statement and HASONEFILTER or HASONEVALUE I believe, it is a pretty common issue.

 

https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

the problem is hasonevalue applies to columns, not measures. 

 

Using a column isn't realistic in this case. I'd like something that does the same thing for a measure. 

Use HASONEFILTER.

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

HASONEFILTER(switch(TRUE(),[Consumption Qty]<[Allocation -10%],[Allocation -10%]-[Consumption Qty],[Consumption Qty]>[Allocation +10%],[Allocation-Consumption]+[Allocation]*.10,0))*[Net Price])

 

Nope. Still asks me for a column. 

The original formula is a composite of measures built from columns in multiple tables. 

 

I need the total to be in terms of product. Add line 1, 2, 3, etc. just like I could do in excel. 

 

Is there an option for "aggregate by product" or something? 

You need to post sample/mock data. What I am referring to is to is to have a table in which you have Product.

 

IF(HASONEFILTER([Product]), calculate one way, calculate another way)

 

It sounds like the issue is that your table is correct except for the totals.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Allocation Table 

[vessel]

[chemical]

[allocation] 

 

allocation bridge (combinding items from allocation and main tables) 

[vessel]

[chemical]

[allocation]

 

main table 

[vessel]

[chemical]

[consumption]

[date] 

 

Allocation measure = sum('allocation bridge'[allocation]) 

consumption qty measure = sumx('main',[qty]*[xqty]) 

 

Refund/Charge = (switch(TRUE(),[Consumption Qty]<[Allocation -10%],[Allocation -10%]-[Consumption Qty],[Consumption Qty]>[Allocation +10%],[Allocation-Consumption]+[Allocation]*.10,0))*[Net Price]

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.