Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hello,
I have a quite peculiar problem. I have a column with values that represents the state of Inventory for each Site (category).
Which means that the most recent one value for each month is always last day per each site per month.
Example
for site 667 for november its going to be value 5 252 235.74 (31/12/2021) but for site 200 its going to be 79 967 894.18 (30/12/2021)
The sum of those values should be 85 220 129.92 which is state of inventory for those two sites per december.
I was able to calculate this with this measure:
Inventory Cost =
VAR _pretable =
ADDCOLUMNS (
SUMMARIZE (
v_factinventorytransactions,
v_dimdate[DateId],
v_factinventorytransactions[SiteId]
),
"InventoryCost", CALCULATE ( AVERAGE ( v_factinventorytransactions[RunningCost] ) )
)
VAR _table =
FILTER (
_pretable,
VAR _MaxDate =
CALCULATE (
MAX ( v_factinventorytransactions[InventoryTransactionDateId] ),
ALLSELECTED ( v_dimdate[DateId] )
)
RETURN
v_dimdate[DateId] = _MaxDate
)
RETURN
SUMX ( _table, [InventoryCost] )
Which works perfectly but I'm wondering if it can be simplyfied. I want it to simplify, because when I want to use this measure inside another one that sums those Inventory Cost values per month for last 3 months and I have wrong answers.
Which means that this Inventory Cost measure works but if I call out this measure in the one below it shows wrong numbers (but other measures, more simply ones work).
Rolling3Months =
VAR _EndDate = MAX(v_dimdate[Date])
VAR _Dates = DATESINPERIOD(v_dimdate[Date], _EndDate, -3, MONTH)
VAR _Cost = [Inventory Cost]
VAR _Inventory = SUMX(_Dates, CALCULATE(_Cost, ALL(v_dimdate[YearMonth])))
RETURN
_Inventory
I'm a little bit stuck and would be super appreciated when someone would pointed out my mistakes/errors here.
I'm also providing sample power BI file with those.
https://we.tl/t-eQSOYHm1ft
Thank you
Solved! Go to Solution.
Hi,
Please try the below measure.
I also attached the pbix file.
Rolling3Months =
VAR _EndDate =
MAX ( v_dimdate[Date] )
VAR _months =
SUMMARIZE (
FILTER (
ALL ( v_dimdate ),
v_dimdate[Date] IN DATESINPERIOD ( v_dimdate[Date], _EndDate, -3, MONTH )
),
v_dimdate[YearMonth]
)
VAR _Inventory =
SUMX ( _months, [Inventory Cost] )
RETURN
IF ( [Inventory Cost] <> BLANK (), _Inventory )
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Hi,
Please try the below measure.
I also attached the pbix file.
Rolling3Months =
VAR _EndDate =
MAX ( v_dimdate[Date] )
VAR _months =
SUMMARIZE (
FILTER (
ALL ( v_dimdate ),
v_dimdate[Date] IN DATESINPERIOD ( v_dimdate[Date], _EndDate, -3, MONTH )
),
v_dimdate[YearMonth]
)
VAR _Inventory =
SUMX ( _months, [Inventory Cost] )
RETURN
IF ( [Inventory Cost] <> BLANK (), _Inventory )
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
43 | |
23 | |
21 | |
15 | |
15 |
User | Count |
---|---|
45 | |
31 | |
30 | |
18 | |
17 |