- Forums
- Get Help with Power BI
- Desktop
- Service
- Report Server
- Integrations with Files and Services
- Mobile Apps
- Developer
- DAX Commands and Tips
- Let's Talk Data
- Custom Visuals Development Discussion
- Community Support
- Community Information
- Community Accounts & Registration
- Using the Community
- Community Feedback
- Training and Consulting
- Dashboard in a Day
- EdX Specific Training Discussion Forum

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Microsoft Power BI Community
- Forums
- Get Help with Power BI
- Desktop
- Calculating Cost Per Unit based off of a total cos...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted

NBOnecall

Regular Visitor

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-18-2019
09:49 AM

Hi,

I am needing help wrapping my head around the best way to apply a percentage based off of the total volume per item of a shipment.

Here is the data I am working with. On this shipment we have 6 different products being shipped and a total of 87 units. The total cost of that Shipment was $167. I would like an output like the one attached at the bottom.

Thank you.

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

jdbuchanan71

Member

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-18-2019
10:45 AM

Hello @NBOnecall

A couple measures to get you to your goal.

Total Volume uses SUMX to calc qty * volume

Total Volume = SUMX ( shipments, shipments[Qty] * shipments[Volume] )

Quantity is just a straight sum

SumQty = Sum(shipments[Qty])

Total cost is done with a cross filter so the shipment id can flow back up the relationship to the cost table.

SumCost = CALCULATE ( SUM ( Cost[Cost] ), CROSSFILTER ( Cost[ShipmentID], shipments[ShipmentID], BOTH ) )

Then the mesure to allocate the cost per shipment across the lines using our [Total Volume] measure

Total Cost = VAR Shipment = SELECTEDVALUE ( shipments[ShipmentID] ) VAR TotalShipmentVolume = CALCULATE ( [Total Volume], ALL ( shipments ), shipments[ShipmentID] = Shipment ) VAR LineVolume = [Total Volume] VAR LinePortion = DIVIDE ( LineVolume, TotalShipmentVolume ) RETURN IF ( HASONEVALUE ( shipments[ShipmentID] ), LinePortion * [SumCost], [SumCost] )

It includes the IF ( HASONEVALE () ) portion so that subtotals on the measure will work correctly.

Finally the per unit cost measure.

Cost Per Item = DIVIDE( [Total Cost] , [SumQty] )

3 REPLIES 3

jdbuchanan71

Member

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-18-2019
10:45 AM

Hello @NBOnecall

A couple measures to get you to your goal.

Total Volume uses SUMX to calc qty * volume

Total Volume = SUMX ( shipments, shipments[Qty] * shipments[Volume] )

Quantity is just a straight sum

SumQty = Sum(shipments[Qty])

Total cost is done with a cross filter so the shipment id can flow back up the relationship to the cost table.

SumCost = CALCULATE ( SUM ( Cost[Cost] ), CROSSFILTER ( Cost[ShipmentID], shipments[ShipmentID], BOTH ) )

Then the mesure to allocate the cost per shipment across the lines using our [Total Volume] measure

Total Cost = VAR Shipment = SELECTEDVALUE ( shipments[ShipmentID] ) VAR TotalShipmentVolume = CALCULATE ( [Total Volume], ALL ( shipments ), shipments[ShipmentID] = Shipment ) VAR LineVolume = [Total Volume] VAR LinePortion = DIVIDE ( LineVolume, TotalShipmentVolume ) RETURN IF ( HASONEVALUE ( shipments[ShipmentID] ), LinePortion * [SumCost], [SumCost] )

It includes the IF ( HASONEVALE () ) portion so that subtotals on the measure will work correctly.

Finally the per unit cost measure.

Cost Per Item = DIVIDE( [Total Cost] , [SumQty] )

NBOnecall

Regular Visitor

Re: Calculating Cost Per Unit based off of a total cost

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-19-2019
07:33 AM

Thank you for replying. I well definelty try your way, but as I was waiting for a reply I went through and worked it a different way that I think gets the same results, but generally tried to based it off of sumif formula of Excel.

For shipment Cost I added a column to my shipment report -

Shipment Cost = CALCULATE(sum('Random Shipment Data Cost'[Cost]),filter('Random Shipment Data Cost','Random Shipment Data Cost'[ShipmentId] = 'hup ShipmentItem'[ShipmentId]))

Then for the volumn of the item I pulled I used lookupvalue to get the volume calculated from another table onto my shipment table

I then calculcated the total vloume as

= 'hup ShipmentItem'[Volume]*'hup ShipmentItem'[QtyReceived]

After some research I was able to find total volume of shipment by using a Calculate, filter formula.

Total Volume for Shipment = CALCULATE(sum('hup ShipmentItem'[Total Volume]),filter('hup ShipmentItem','hup ShipmentItem'[ShipmentId]= Earlier ('hup ShipmentItem'[ShipmentId])))

And then total Cost and Total Cost per unit was a simple multiply and divide formula.

My output looked like this -

Now my question to @jdbuchanan71, what way is better and for what reason. I am still pretty new to PowerBI so anything helps.

Thanks!

jdbuchanan71

Member

Re: Calculating Cost Per Unit based off of a total cost

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-19-2019
07:47 AM

Hello @NBOnecall

For me the "better" way is the one that works that I understand. Sometimes the layers of formulas can get confusing and I want to be able to predict the behavior of the measures.

If both of the methods perform equally well (calculate quickly in visuals) then I would use the one you came up with on your own.

Cheers!