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
michalintive
Regular Visitor

Power BI subscrating Matrix view.

Hi all,

 

I need to create a new column with resoult of subsctracting two columns in Matrix view. I've tried to do it by guides in this community but I wasnt able to do it.Untitled.jpg

 

I need to do calculation:

A Revenue - B Project Costs = x

 

Next I need to:

X / A Revenue = ....

 

Do you have any ideas how to do that?

 

Much thanks for your help.

1 ACCEPTED SOLUTION

@michalintive,

 

You may refer to the following measures.

Revenue =
CALCULATE ( SUM ( Table1[Value] ), Table1[Cost_Center_2] = "Revenue" )
Costs =
CALCULATE ( SUM ( Table1[Value] ), Table1[Cost_Center_2] = "B Project Costs" )
X =
[Revenue] - [Costs]
Percent =
DIVIDE ( [X], [Revenue] )
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

8 REPLIES 8
Anonymous
Not applicable

Hi,

 

Are you familiair with the difference between a calculated column and a calculated measure? 

 

A calculated column can only access columns that are in the same table, or can be accessed via the RELATED() function from the many to one side (so only one value is returned). The result of a calculated column is stored in memory and is calculated on data refresh or when changed.

 

A calculated measure is calculated each time based on the dimensions it needs to be calculated for. So it is not "part" of a table.

newmeasure.png

In your situation you can create two measures like

Budget = SUM(ProjectBudget[ProjectBudget])

Cost = SUM(ProjectCost[ProjectCost])

 

Then create a third measure that does the calculation of choice.

Margin = [Budget] - [Cost]

 

 

 

 

 

If you want to have it split per project for example you could import a table that has both budget and cost in the same table and substract them with a calculated column. You can also import a second table that shares the same dimension (Project) and use measures like described. Depends on the granularity and if they use the same dimensions.

 

budget.JPG

 

Good luck! 

Is there any possibility to make budget as you wrote but adding a criteria?

For example I need to calculate it in the way

 

Revenue = SUM(Table1[Value]) & Filter(Table1[Cost_Center_2]='Revenue')

Costs = Sum(Table1[Value] & Filter(Table1[Cost_Center_2]='B Project Costs') ?

 

Guy which projected this database puted all values in one column revenue and costs.

@michalintive,

 

You may refer to the following measures.

Revenue =
CALCULATE ( SUM ( Table1[Value] ), Table1[Cost_Center_2] = "Revenue" )
Costs =
CALCULATE ( SUM ( Table1[Value] ), Table1[Cost_Center_2] = "B Project Costs" )
X =
[Revenue] - [Costs]
Percent =
DIVIDE ( [X], [Revenue] )
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.
Anonymous
Not applicable

@v-chuncz-msft, this also works fine but be aware that these Revenue & Cost measures will deliver the same value even for rows with, for example, Gross sales. As long as you don't put those together in a visual its ok and even shorter code. If you only want the Revenue to be calculated for the rows with the Revenue labels use the FILTER() clause.

 

The FILTER clause will only give the rows with Revenue as label to the calculation of SUM(Table1[Value]). So if there is a row for Revenue and Cost it will only calculates for one row. 

 

Difference between Revenue with FILTER and without:

filters.JPG

 

The totals are displayed correct but the € 100 at the Cost category is incorrect and can be misleading.

 

@michalintive, choose your desired solution! The left one is described in @v-chuncz-msft post, the right one in my post. 

Hi all,

 

Thanks for all solutions. There is one more thing. Desktop PowerBI shows me now measures after each column:

Capture1.JPG

Is there any way to show columns with measures only after Cost Center 2, in the way as below?

Capture2.JPG

 

Much apriciate for your help!


Ok, problem solved, I hidden the columns 🙂 Thank you all!!

Anonymous
Not applicable

Sure, no problem.

 

Example based on this table:

costrevenue.JPG

 

Result:

result.JPG

 

Code:

Revenue = 
CALCULATE(
	SUM(Table1[Value]);
	FILTER(
		Table1;
		Table1[Category]="Revenue"
	)
)

Costs = 
CALCULATE(
	SUM(Table1[Value]);
	FILTER(
		Table1;
		Table1[Category]="Costs"
	)
)

 

 

 

michalintive
Regular Visitor

Thing I need to match in my DB is a project number and organizational unit. I can't add or subscrat column to column.

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.