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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
jkoclejda
Helper I
Helper I

Subtract a value from one category and add to another

Hi!

I have a table like below and I want to subtract 40% from the quantity of the pears and add 10% to the quantity of the apples.

 

Fruit TypeQuantity
Pears20
Cherries10
Bananas40
Apples15
Summary85

 

It's just an egxample - in fact i must do it with sessions for source / medium from Google Analytics but but I figured it would be easier to explain. Coming back to the fruit example, I wrote the following calculation:

 

Fruit Quantity =
VAR _Pears = CALCULATE((SUM('Fruits'[Quantity]) * 0.4), 'Fruits'[Fruit Type] = "Pears")
VAR _Apples = CALCULATE((SUM('Fruits'[Quantity]) * 0.1), 'Fruits'[Fruit Type] = "Apples")
RETURN
CALCULATE(
SUM('Fruits'[Quantity]) - _Pears +_Apples
)
 
I thought the quantity would only be added / subtracted for the fruits specified earlier in the variables. Unfortunately, this changes the quantity for all fruits.
 
Does anyone have an idea how to write such a calculation that only the quantity of apples and pears change, and the rest remain original?
1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

@jkoclejda try this for a quick fix to your formula:

 

Fruit Quantity = 
VAR _Pears = CALCULATE((SUM('Fruits'[Quantity]) * 0.4), KEEPFILTERS('Fruits'[Fruit Type] = "Pears"))
VAR _Apples = CALCULATE((SUM('Fruits'[Quantity]) * 0.1), KEEPFILTERS('Fruits'[Fruit Type] = "Apples"))
RETURN
CALCULATE(
SUM('Fruits'[Quantity]) - _Pears +_Apples
)

 



2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

View solution in original post

3 REPLIES 3
SpartaBI
Community Champion
Community Champion

@jkoclejda try this for a quick fix to your formula:

 

Fruit Quantity = 
VAR _Pears = CALCULATE((SUM('Fruits'[Quantity]) * 0.4), KEEPFILTERS('Fruits'[Fruit Type] = "Pears"))
VAR _Apples = CALCULATE((SUM('Fruits'[Quantity]) * 0.1), KEEPFILTERS('Fruits'[Fruit Type] = "Apples"))
RETURN
CALCULATE(
SUM('Fruits'[Quantity]) - _Pears +_Apples
)

 



2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

It works perfect! Thank you very much 🙂

@jkoclejda my pleasure 🙂

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.