Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hi,
I always struggle with calculating where are no data points.
Scenario:
There Item Ledger entries for incoming and outgoing quantities, but not for every day. (Posting Date of this table is connected to calendar table - Many to One).
The first data entry is always the warehouse incoming product quantity.
Receipt Date =
CALCULATE(
MIN(ILE[Posting Date]),
FILTER(
ILE,
ILE[ItemLotNo] = EARLIER(ILE[ItemLotNo])
)
)
Based on this date, I calculate the days difference between the line date an the incoming date.
age in days =
DATEDIFF(
MIN(ILE[Receipt Date]),
MAX('Calendar'[Date]),
DAY
)
To get the stock per day, I cummulate the Item Ledger Entry Quantity.
Cumulative inventory =
CALCULATE(
SUM(ILE[Quantity]),
FILTER(
ALLSELECTED('Calendar'[Date]),
'Calendar'[Date] <= MAX('Calendar'[Date])
)
)
Now I want to calculate the costs per day based on a cost scale table (between these count of days, it cost that much).
Inventory costs per day =
VAR d = MAX ( 'Calendar'[Date] )
RETURN
SUMX (
SUMMARIZE (
ILE,
ILE[ItemLotNo],
"InDate", MIN ( ILE[Receipt Date] )
),
VAR _item = [ItemLotNo]
VAR _inDate = [InDate]
VAR _age = DATEDIFF ( _inDate, d, DAY )
// passenden Satz aus der Kostenstaffel suchen
VAR _rate =
MAXX (
FILTER ( 'Cost scale TEST', _age >= 'Cost scale TEST'[cost] && _age <= 'Cost scale TEST'[to] ),
'Cost scale TEST'[cost]
)
VAR _stockAsOfD =
CALCULATE (
[Cumulative inventory],
FILTER ( ALL ( ILE[Posting Date]), ILE[Posting Date] <= d ),
ILE[ItemLotNo] = _item
)
RETURN COALESCE ( _stockAsOfD, 0 ) * COALESCE ( _rate, 0 )
)
Problem now is that days where there is no item ledger entry are not calculated with the corresponding costs.
I cant find the problem here.
Thx for any advise!
PS: Example Data
Item Ledger Entry
Posting DateItemLotNoQuantityReceipt Date
|
Cost Scale
from dayto daycost per day
|
Calendar
Date
|
Solved! Go to Solution.
Hi @dEllE
I reproduced the scenario on my end using sample data and it worked successfully. To help you better understand the implementation, I’ve attached the .pbix file for your reference. Please take a look at it and let me know your observations.
I hope this information is helpful. . If you have any further questions, please let us know. we can assist you further.
Regards,
Microsoft Fabric Community Support Team.
Hi @dEllE
I reproduced the scenario on my end using sample data and it worked successfully. To help you better understand the implementation, I’ve attached the .pbix file for your reference. Please take a look at it and let me know your observations.
I hope this information is helpful. . If you have any further questions, please let us know. we can assist you further.
Regards,
Microsoft Fabric Community Support Team.
THX,
first of all. I still had the connection between Calendar Date and Posting Date active, as I meantioned in my OP.
Did not know to cut this.
Now it works.
But I don't understand what you are calculating with the "Inventory Cost per Day 2" Measure.
The correct calculation is already in the ""Inventory Cost per Day" Measure.
But thank you very very much!!!!!!!!
Hi @dEllE
Thank you for reaching out to the Microsoft Fabric Community Forum.
The issue occurs because the iteration is defined over the Item Ledger Entry table. On calendar days without corresponding ledger rows, the iteration set is empty and the calculation returns blank.
Try the modified code below, which builds the iteration from the set of lots (ignoring the date filter). For each calendar day, it determines the stock as of that date and applies the appropriate cost rate, ensuring results are calculated even when no ledger entries exist:
Inventory Cost per Day :=
VAR d =
MAX ( 'Calendar'[Date] )
VAR Lots =
CALCULATETABLE (
VALUES ( ILE[ItemLotNo] ),
REMOVEFILTERS ( 'Calendar'[Date] )
)
RETURN
SUMX (
Lots,
VAR _lot =
ILE[ItemLotNo]
VAR _inDate =
CALCULATE (
MIN ( ILE[Receipt Date] ),
ILE[ItemLotNo] = _lot,
REMOVEFILTERS ( 'Calendar'[Date] )
)
VAR _age =
DATEDIFF ( _inDate, d, DAY ) + 1
VAR _rate =
CALCULATE (
MAX ( 'Cost scale'[CostPerDay] ),
FILTER (
ALL ( 'Cost scale' ),
_age >= 'Cost scale'[FromDay]
&& _age <= 'Cost scale'[ToDay]
)
)
VAR _stockAsOfD =
CALCULATE (
SUM ( ILE[Quantity] ),
ILE[ItemLotNo] = _lot,
FILTER ( ALL ( ILE[Posting Date] ), ILE[Posting Date] <= d )
)
RETURN MAX ( 0, COALESCE ( _stockAsOfD, 0 ) ) * COALESCE ( _rate, 0 )
)
I hope this information is helpful. . If you have any further questions, please let us know. we can assist you further.
Regards,
Microsoft Fabric Community Support Team.
Hi,
thx for this information. I kind of understand the problem.
Now it is at least calculated for every single day, but there are no costs at all.
could you pls provide some sample data and expected output?
Proud to be a Super User!
Hi,
just take 3 or 4 lines of the item ledger entry table (seen on the last picture).
Expected output is like shown on the last picture.
The red marked dates should have calculated costs on every day.
for example 02.12.2024 should be 90 €, because stock of quntity 90 costs 1€ per day, if it is longer than 10 days in warehouse.
Please do not make us manually encode those.
Example Data:
Cost Scale
|
Item Ledger Entry
|
Calendar
|
Hi,
sorry, I posted the test data in my original post.
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!