I perform an analysis where we look at the materials that we produced in the current month and compare the usage of components to the same period last year.
The difference calculation works when a product was produced both this and last year. However, I need to exclude materials from the calculation that were only produced this year but not last year or last year but not this year.
I’ve spent a day and a half and I’m not close to an answer. It seems that if I build the logic into the iterating calculations, it applies it to the component/material level instead of the total material level.
How do I exclude the materials for the specified condition?
Do I need to modify the code or add new code elsewhere?
Component Difference =
CALCULATE (
SUMX (
SUMMARIZE (
'Unique Mat Comp Plt',
'Unique Mat Comp Plt'[Material],
'Unique Mat Comp Plt'[Component Material]
),
IF (
[Component LBs CY] - [CY LBS at PY Rate] = 0,
- [Component LBS PY],
[Component LBs CY] - [CY LBS at PY Rate]
)
)
)
![No%20PY%20volume|689x222](upload://qgLFJ3GxMqo0DFINYCs2WqwCSuP.png)
When I want figures for the “current month”, “Current Year”, “Current Quarter” etc from a fact table I normally use a month offset in the Date table and then write measures filtered by the columns in the Date table.
For example, below is a measure for Customer Sales Last Month. So an offset of -1 shown below which represents Last Month and 0 = current month.
Customer Sale Invoices This Month =
IF (NOT
( ISBLANK ( [Customer Sale Invoices]) ),
CALCULATE
([Customer Sale Invoices],
‘DimCalendar’[CurrentMonthOffset] = 0 ))
Customer Sale Invoices Last Month =
IF (NOT
( ISBLANK ( [Customer Sale Invoices]) ),
CALCULATE
([Customer Sale Invoices],
‘DimCalendar’[CurrentMonthOffset] = -1 ))
Then you can work out the difference between each measure for a variance.
Try and break down each measure and see if you can get the right results at a total level.