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
AndrewH1
New Member

Calculation over specific rows

Hi,

I'm still new to Power BI, and right now I have a problem with what I believe is data being summed at the wrong time. I have a table that is organized by region, date, commodity, scenario (either the forecast or budget), metric (either volume or price) and then there is the value. Each row is one of those combinations, i.e. the forecasted price, budgeted price, or forecasted volume. I'm trying to calculate the future budget impact using (Forecast - budget) * volume, but I am having trouble with the result being far off when more than one region/commodity/date is selected.

 

The original solution, which I believe causes it to sum the data before doing the calculation is Impact = ((CALCULATE(Sum(Main[Value]), Main[Scenario]="Forecast", Main[Metric]="Price")-CALCULATE(Sum(Main[Value]), Main[Scenario]="Budget",Main[Metric]="Price")))*(CALCULATE(Sum(Main[Value]), Main[Scenario]="Forecast", Main[Metric]="Volume")).

 

Instead I want it to do the calculation, then sum over the possibilities. (I believe it does (Σforecast - Σbudget) * Σvolume, when I want Σ((forecast - budget) * volume)) ) I've been trying to filter out the different types of values, but have had no luck so far. Any help or solution to this would be amazing.

 

Thanks!

 

Example table

PBICommunity.PNG

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@AndrewH1,

 

You may first Merge Columns and Pivot Column in Query Editor, then use SUMX Function in DAX.

Community Support Team _ Sam Zha
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

2 REPLIES 2
v-chuncz-msft
Community Support
Community Support

@AndrewH1,

 

You may first Merge Columns and Pivot Column in Query Editor, then use SUMX Function in DAX.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
BKirsch12
Resolver II
Resolver II

I've found the using multiple measures makes the code easier to follow, as well as either to work with. I'd recommend you use your current code to make 4 measures.

 

Forecasted Price = CALCULATE(Sum(Main[Value]), Main[Scenario]="Forecast", Main[Metric]="Price")

 

Budgeted Price =CALCULATE(Sum(Main[Value]), Main[Scenario]="Budget",Main[Metric]="Price")

 

Forecasted Volume =CALCULATE(Sum(Main[Value]), Main[Scenario]="Forecast", Main[Metric]="Volume")

 

Your Calculation = (Forecasted Price - Budgeted Price) * Forecasted Volume

 

As far as displaying the information, you'll need to decide how to do that (By Commodity Type, etc.). 

 

Let me know if this helps.

 

 

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.