cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
SaraM
Frequent Visitor

Subtraction values from one column based on different criteias

I have a table that I want to subtract values of " Estimated cost" column based on clasee of Estiame and Description.

Here is a smple of my table. can you please help me with the query. 

SaraM_0-1636039902022.png

I want column "cost variance" to subtract line items with the same discriptin & Cost Category between class of estimate 4 and 3. 

Thank you!

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @SaraM ,

 

In Power Query you can select your [CLASS OF ESTIMATE] column, then go to the Transform tab > Pivot Column.

Set [Estimated Cost] as the Values Column, and set the aggregator to SUM under Advanced Options.

This will give you the different estimate classes as columns that you can add/subtract across.

 

The more common way to achieve this, however, would be to load your table to the data model as it is, then write a measure against it, something like this:

_costVariance =
VAR __cost3 =
CALCULATE(
  SUM(yourTable[Estimated Cost]),
  yourTable[CLASSOFESTIMATE] = 3
)
VAR __cost4 =
CALCULATE(
  SUM(yourTable[Estimated Cost]),
  yourTable[CLASSOFESTIMATE] = 4
)
RETURN
__cost4 - __cost3

 

Then you would add this measure to your visuals along with whichever categories/descriptions etc. you want and Power BI will agregate the variance for each dimension roup for you.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

3 REPLIES 3
BA_Pete
Super User
Super User

Hi @SaraM ,

 

In Power Query you can select your [CLASS OF ESTIMATE] column, then go to the Transform tab > Pivot Column.

Set [Estimated Cost] as the Values Column, and set the aggregator to SUM under Advanced Options.

This will give you the different estimate classes as columns that you can add/subtract across.

 

The more common way to achieve this, however, would be to load your table to the data model as it is, then write a measure against it, something like this:

_costVariance =
VAR __cost3 =
CALCULATE(
  SUM(yourTable[Estimated Cost]),
  yourTable[CLASSOFESTIMATE] = 3
)
VAR __cost4 =
CALCULATE(
  SUM(yourTable[Estimated Cost]),
  yourTable[CLASSOFESTIMATE] = 4
)
RETURN
__cost4 - __cost3

 

Then you would add this measure to your visuals along with whichever categories/descriptions etc. you want and Power BI will agregate the variance for each dimension roup for you.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




SaraM
Frequent Visitor

@BA_Pete  Thank you so much. It worked perfectly with both, but I went with the measure. 

 

Thank you!

@SaraM ,

 

No problem. Happy to get it sorted for you so quickly.

Don't forget to mark the post that solved your issue as the solution. This helps others with the same question find the answer quicker when searching.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors