Reputation: 27
As the model in the table, I have the bill of materials table as the fact table and the price and demand tables and dimensions,
I need to create 1- measure to calculate the total required quantity per item code, 2- Measure the total spendings per SKU # as per the demand table and price table which are not directly related.
I was trying to use related functions however it was not matching the data which should claculated by the measure
Upvotes: 0
Views: 50
Reputation: 8148
To make DAX code easy and fast, you need to re-design your data model. You current model has several mistakes:
As a general rule, if a field is used for filtering reports (for example, as a slicer), then it belongs to a dimension. If a field is used as an input in calculations, it belongs to a fact table.
Here is how I would change your data model:
Then DAX measures become very simple.
For total required Qty of Items:
Required Item Qty = SUM ( BOM[Item Qty])
For the measure you asked (total required cost of items):
Required Item Cost =SUMX( BOM, BOM[Item Qty] * BOM[Price] * BOM[SKU Qty])
And your report might look like this:
with the ability to drill down:
The only thing you need to be careful is demand. Since moving SKU Qty to BOM duplicates numbers, you can't simply sum them up to show total demand. You need to de-duplicate numbers first, for example:
Total Demand =
SUMX (
SUMMARIZE ( BOM, BOM[SKU], BOM[SKU Qty] ),
BOM[SKU Qty]
)
which gives you this report:
Upvotes: 1