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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

Multiple totals on matrix

Hi there,

Please take a look at the PBIX and this photo and see if you can help me

I have one table name account and I seperate it into two tables but the requirement was if I can merge these two

Tables into one (see bottom page the excel version) - Can I have two seperate totals on same column in one matrix?

I solve it with t-SQL 4 itterations one for billing one for cost one for total cost and one for billing - ToalCost and it worls but I would like to do it in DAX

Thanks,

Ed Dror


PBIX.JPGAccount.JPG

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

hi, @Anonymous 

I'm afraid that add an additional total row is not available for now.

And you may try this way to add a new custom row not a "total" row:

Step1:

Use this formula to create a new category dim table.

Dim CatName = UNION(SUMMARIZE(Account,Account[Category],Account[CatName]),ROW("Category",99,"CatName","Total Cost"))

Step2:

Create a relationship with Account table

Step3:

Adjust your formula as below:

Original = 
VAR Billing = Calculate(
Sum('Account'[Amount])
,Account[Category] = 0)

VAR Categories = Calculate(
Sum(Account[Amount])
,Account[Category] <> 0)
Return
IF(SELECTEDVALUE('Dim CatName'[CatName])="Total Cost",CALCULATE(SUM(Account[Amount]),FILTER(ALLSELECTED(Account),Account[Category] <> 0)),
 ABS(Billing - Categories))

Result:

3.JPG

By the way, you could use sort by column to sort the column order

https://docs.microsoft.com/en-us/power-bi/desktop-sort-by-column

 

here is pbix file, please try it.

 

Best Regards,

Lin

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

4 REPLIES 4
v-lili6-msft
Community Support
Community Support

hi, @Anonymous 

I'm afraid that add an additional total row is not available for now.

And you may try this way to add a new custom row not a "total" row:

Step1:

Use this formula to create a new category dim table.

Dim CatName = UNION(SUMMARIZE(Account,Account[Category],Account[CatName]),ROW("Category",99,"CatName","Total Cost"))

Step2:

Create a relationship with Account table

Step3:

Adjust your formula as below:

Original = 
VAR Billing = Calculate(
Sum('Account'[Amount])
,Account[Category] = 0)

VAR Categories = Calculate(
Sum(Account[Amount])
,Account[Category] <> 0)
Return
IF(SELECTEDVALUE('Dim CatName'[CatName])="Total Cost",CALCULATE(SUM(Account[Amount]),FILTER(ALLSELECTED(Account),Account[Category] <> 0)),
 ABS(Billing - Categories))

Result:

3.JPG

By the way, you could use sort by column to sort the column order

https://docs.microsoft.com/en-us/power-bi/desktop-sort-by-column

 

here is pbix file, please try it.

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Lin,

 

After testing it with one category as negative amount the expected result don't match 

I added another toal cost to the Dim

Dim CatName = UNION(SUMMARIZE(Account,Account[Category],Account[CatName]),ROW("Category",99,"CatName","Total Cost"),ROW("Category",999,"CatName","Cost Margin"))

And then I did

Original =
VAR Billing = Calculate(Sum('Account'[Amount]),Account[Category] = 0)
VAR Labor = Calculate(Sum(Account[Amount]),Account[Category] = 1)
VAR QM = Calculate(Sum(Account[Amount]),Account[Category] = 3)
VAR Misc = Calculate(Sum(Account[Amount]),Account[Category] = 4)
VAR Sub = Calculate(Sum(Account[Amount]),Account[Category] = 5)
VAR Equip = Calculate(Sum(Account[Amount]),Account[Category] = 6)
VAR Vendor = Calculate(Sum(Account[Amount]),Account[Category] = 7)
VAR Other = Calculate(Sum(Account[Amount]),Account[Category] = 😎
Var TC = Labor + QM + Misc + Sub + Equip + Vendor + Other

Return
IF(SELECTEDVALUE('Dim CatName'[CatName])="Total Cost",CALCULATE(SUM(Account[Amount]),FILTER(ALLSELECTED(Account),Account[Category] <> 0)),
IF(SELECTEDVALUE('Dim CatName'[CatName])="Cost Margin",CALCULATE(SUM(Account[Amount]),FILTER(ALLSELECTED(Account),Account[Category] <> 0)),
(Billing - TC)))
But is not working (I change Equipment and vendor Equipment to negative amount)
Thanks,
Ed Dror
 
 
Anonymous
Not applicable

Lin,

 

It works,

Thank you

Ed Dror

 

Anonymous
Not applicable

One more think

I got the total for table A by doing this

Original =
VAR Billing = Calculate(
Sum('Account'[Amount])
,Account[Category] = 0)

VAR Categories = Calculate(
Sum(Account[Amount])
,Account[Category] <> 0)
Return ABS(Billing - Categories)
Thanks,
Ed Dror

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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