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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
larbpup
Frequent Visitor

Trouble Calculating Subtotals using All functions

I am attempting to calculate the % of the material cost of a part based on the overall material cost of all parts in a given location. I assumed it would be straightforward with <single part cost>/<overall cost> but I am having trouble getting the denominator using Calculate and All functions, can anyone tell me what I am doing wrong?

 

I have one table with sales orders like so:

 

Warehouse PartId Invoice Date RepId CustomerId Sale Amt Qty
1 359 112 1/6/2023 1 878 $6,453.10 1
2 372 113 1/6/2023 2 878 $19,327.44 1

 

I have several other dimension tables connected to this, but most importantly I have a Part table with associated costs that is linked in a Many to 1 relationship to the Sales Order table:

 

PartId Unit Cost
359 $5,150
372 $15,500

 

First I create a measure for the cost unit cost: UnitCost = sumx('Part Table','Part Table'[Unit Cost]).

I also create a Qty measure just for convencience: OrderQty = sumx('Sales Orders','Sales Orders'[Qty])

 

Then I calculate the material cost for the order by multiplying Qty * Cost but I need to do some extra DAX in order to ensure that it multiplies and then sums (it was giving me incorrect totals because it was summing and then multiplying when I did [UnitCost] * [OrderQty]).

 

larbpup_1-1675996975862.png

 

The ExtCost measure: 

ExtCost = sumx(Values('Sales Orders'[PartId]),CALCULATE([UnitCost] * [OrderQty)).


So now I would like to calculate % cost for a given sales order at a location: %ofCost = Divide([ExtCost],[TotalLocationCost]) but I am failing to get the correct amount for TotalLocationCost. I assume it is some combination of Calculate and All but I tried 
[TotalLocationCost] = calculate([ExtCost],ALLSELECTED('Sales Orders'[Warehouse])) and it is just returning the same amount as Ext Cost and thus my % is always 100%.
 
I would like Warehouse Ext Cost to be $41,200 for each row.
larbpup_4-1675998019205.png

 

 


I still have a bit of trouble wrapping my head around the ALL functions, can anyone point me in the right direction?
 
Thanks.
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Use ALLSELECTED('Sales Orders') or REMOVEFILTERS() on the warehouse column.

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

Use ALLSELECTED('Sales Orders') or REMOVEFILTERS() on the warehouse column.

Helpful resources

Announcements
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.