Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
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 )
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 )
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
11 | |
11 | |
10 | |
9 | |
8 |
User | Count |
---|---|
17 | |
12 | |
11 | |
11 | |
11 |