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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Rob_B
Helper I
Helper I

Sum What-if parameter value with column value with IF function

I'm trying to create a measure that adds a what-if parameter ('PA Cost Adjustment'[PA Cost Adjustment Value])

to a column ('Forecast'[Budget]) only when another column is a certain value ('Forecast'[Sector]="B").

 

In Excel, I would use a formula like this:

 

=IF([@Sector]="B",[@Budget]+PA Cost Adjustment Value,[@Budget])

 

where PA Cost Adjustment Value is a named range.

 

I tried creating a measure with an IF statement

 

Scenario Budget = IF(Contains(Forecast|Forecast[Sector]|"B")|SUM(Forecast[Budget])+'PA Cost Adjustment'[PA Cost Adjustment Value]|SUM(Forecast[Budget]))

 

which will calculate the correct value for a single year, but if you sum up all years, the what-if parameter is only added once instead of 4 times.

 

Here's a sample of the table ('Forecast')

SectorYearBudget
A2020100
A2021200
A2022300
A2023400
B20201
B20212
B20223
B20234
C20201000
C20212000
C20223000
C20234000

 

I'm sure I'm making a rookie mistake but I despite hours of googling solutions and watching videos, I can't figure it out! Thanks in advance for your help!

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Rob_B , Create a new measure like

sumx(summarize(Table,table[Sector],table[Year],"_1",[Scenario Budget]),[_1])

View solution in original post

MarcoPessina
Resolver IV
Resolver IV

Hi @Rob_B ,

a measure like this should work:

 

Scenario Budget = CALCULATE(
SUMX(MyBudgetTable, IF(MyBudgetTable[Sector]="B", MyBudgetTable[Budget] + max('PA Cost Adjustment Value'[PA Cost Adjustment Value]), MyBudgetTable[Budget])
)
)
 
Hope it helps.
Cheers,
Marco

View solution in original post

5 REPLIES 5
MarcoPessina
Resolver IV
Resolver IV

Hi @Rob_B ,

a measure like this should work:

 

Scenario Budget = CALCULATE(
SUMX(MyBudgetTable, IF(MyBudgetTable[Sector]="B", MyBudgetTable[Budget] + max('PA Cost Adjustment Value'[PA Cost Adjustment Value]), MyBudgetTable[Budget])
)
)
 
Hope it helps.
Cheers,
Marco
amitchandak
Super User
Super User

@Rob_B , Create a new measure like

sumx(summarize(Table,table[Sector],table[Year],"_1",[Scenario Budget]),[_1])

@amitchandak thanks, this works! Now I'll have to study up on the Summarize function to understand why!

@Rob_B , It is because or Row Context. every measure recalculates the grand total. When we use if or some comparison, it actually does not have value for grand total, to Grand total is different. This formula(Summarize) force grand total to calculated from a row level.

 

Thanks for explaining @amitchandak@MarcoPessina's solution using SUMX with IF and MAX functions also works (had to remove the word "value" to refer to the what-if parameter column and not the measure). Is the a benefit to using summarize over the IF & MAX approach?

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.