Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
dEllE
Helper I
Helper I

Calculating daily costs on cummulated quantity when there are no daily data entries

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).

 

dEllE_0-1756106397471.png


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).

dEllE_1-1756106592793.png

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.

dEllE_2-1756106854660.png

I cant find the problem here.

Thx for any advise!

 

PS: Example Data

Item Ledger Entry

Posting DateItemLotNoQuantityReceipt Date
22.11.20240081642400549022.11.2024
09.12.2024008164240054-122.11.2024
09.12.2024008164240054-122.11.2024
09.12.2024008164240054-122.11.2024
09.12.2024008164240054-122.11.2024
09.12.2024008164240054-122.11.2024
09.12.2024008164240054-122.11.2024
09.12.2024008164240054-122.11.2024
09.12.2024008164240054-122.11.2024
10.12.2024008164240054-122.11.2024
10.12.2024008164240054-122.11.2024
10.12.2024008164240054-122.11.2024
10.12.2024008164240054-122.11.2024
10.12.2024008164240054-122.11.2024
10.12.2024008164240054-122.11.2024
11.12.2024008164240054-122.11.2024
11.12.2024008164240054-122.11.2024
11.12.2024008164240054-122.11.2024
12.12.2024008164240054-122.11.2024
12.12.2024008164240054-122.11.2024
12.12.2024008164240054-122.11.2024
12.12.2024008164240054-122.11.2024
12.12.2024008164240054-122.11.2024
12.12.2024008164240054-122.11.2024
13.12.2024008164240054-122.11.2024
16.12.2024008164240054-122.11.2024
16.12.2024008164240054-122.11.2024
16.12.2024008164240054-122.11.2024
16.12.2024008164240054-122.11.2024
16.12.2024008164240054-122.11.2024
16.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
18.12.2024008164240054-122.11.2024
18.12.2024008164240054-122.11.2024
18.12.2024008164240054-122.11.2024
19.12.2024008164240054-122.11.2024
19.12.2024008164240054-122.11.2024
19.12.2024008164240054-122.11.2024
19.12.2024008164240054-122.11.2024
19.12.2024008164240054-122.11.2024
19.12.2024008164240054-122.11.2024
19.12.2024008164240054-122.11.2024
20.12.2024008164240054-122.11.2024
20.12.2024008164240054-122.11.2024
20.12.2024008164240054-122.11.2024
23.12.2024008164240054-122.11.2024
23.12.2024008164240054-122.11.2024
23.12.2024008164240054-122.11.2024
23.12.2024008164240054-122.11.2024
23.12.2024008164240054-122.11.2024
23.12.2024008164240054-122.11.2024
23.12.2024008164240054-122.11.2024
23.12.2024008164240054-122.11.2024
23.12.2024008164240054-122.11.2024
23.12.2024008164240054-122.11.2024
24.12.2024008164240054-122.11.2024
24.12.2024008164240054-122.11.2024
24.12.2024008164240054-122.11.2024
24.12.2024008164240054-122.11.2024
24.12.2024008164240054-122.11.2024
27.12.2024008164240054-122.11.2024
27.12.2024008164240054-122.11.2024
27.12.2024008164240054-122.11.2024
27.12.2024008164240054-122.11.2024
27.12.2024008164240054-122.11.2024
27.12.2024008164240054-122.11.2024
27.12.2024008164240054-122.11.2024
27.12.2024008164240054-122.11.2024
27.12.2024008164240054-122.11.2024
30.12.2024008164240054-122.11.2024
30.12.2024008164240054-122.11.2024
30.12.2024008164240054-122.11.2024
30.12.2024008164240054-122.11.2024
30.12.2024008164240054-122.11.2024
30.12.2024008164240054-122.11.2024
30.12.2024008164240054-122.11.2024
30.12.2024008164240054-122.11.2024
30.12.2024008164240054-122.11.2024
30.12.2024008164240054-122.11.2024

 

Cost Scale

from dayto daycost per day
0100
11201
21302
313603
36199995

 

Calendar

Date
22.11.2024
23.11.2024
24.11.2024
25.11.2024
26.11.2024
27.11.2024
28.11.2024
29.11.2024
30.11.2024
01.12.2024
02.12.2024
03.12.2024
04.12.2024
05.12.2024
06.12.2024
07.12.2024
08.12.2024
09.12.2024
10.12.2024
11.12.2024
12.12.2024
13.12.2024
14.12.2024
15.12.2024
16.12.2024
17.12.2024
18.12.2024
19.12.2024
20.12.2024
21.12.2024
22.12.2024
23.12.2024
24.12.2024
25.12.2024
26.12.2024
27.12.2024
28.12.2024
29.12.2024
30.12.2024
1 ACCEPTED SOLUTION
v-karpurapud
Community Support
Community Support

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.
 

View solution in original post

9 REPLIES 9
v-karpurapud
Community Support
Community Support

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!!!!!!!!

v-karpurapud
Community Support
Community Support

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.

 

dEllE_0-1756195412424.png

 

ryan_mayu
Super User
Super User

could you pls provide some sample data and expected output?





Did I answer your question? Mark my post as a solution!

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.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Example Data:

 

 

Cost Scale

from dayto daycost per day
0100
11201
21302
313603
36199995

 

Item Ledger Entry


Posting DateItemLotNoQuantityReceipt Date
22.11.20240081642400549022.11.2024
09.12.2024008164240054-122.11.2024
09.12.2024008164240054-122.11.2024
09.12.2024008164240054-122.11.2024
09.12.2024008164240054-122.11.2024
09.12.2024008164240054-122.11.2024
09.12.2024008164240054-122.11.2024
09.12.2024008164240054-122.11.2024
09.12.2024008164240054-122.11.2024
10.12.2024008164240054-122.11.2024
10.12.2024008164240054-122.11.2024
10.12.2024008164240054-122.11.2024
10.12.2024008164240054-122.11.2024
10.12.2024008164240054-122.11.2024
10.12.2024008164240054-122.11.2024
11.12.2024008164240054-122.11.2024
11.12.2024008164240054-122.11.2024
11.12.2024008164240054-122.11.2024
12.12.2024008164240054-122.11.2024
12.12.2024008164240054-122.11.2024
12.12.2024008164240054-122.11.2024
12.12.2024008164240054-122.11.2024
12.12.2024008164240054-122.11.2024
12.12.2024008164240054-122.11.2024
13.12.2024008164240054-122.11.2024
16.12.2024008164240054-122.11.2024
16.12.2024008164240054-122.11.2024
16.12.2024008164240054-122.11.2024
16.12.2024008164240054-122.11.2024
16.12.2024008164240054-122.11.2024
16.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
17.12.2024008164240054-122.11.2024
23.12.2024008164240054-122.11.2024
23.12.2024008164240054-122.11.2024
23.12.2024008164240054-122.11.2024
23.12.2024008164240054-122.11.2024
23.12.2024008164240054-122.11.2024
23.12.2024008164240054-122.11.2024
24.12.2024008164240054-122.11.2024
24.12.2024008164240054-122.11.2024
24.12.2024008164240054-122.11.2024
24.12.2024008164240054-122.11.2024
24.12.2024008164240054-122.11.2024
27.12.2024008164240054-122.11.2024
27.12.2024008164240054-122.11.2024
27.12.2024008164240054-122.11.2024
27.12.2024008164240054-122.11.2024
27.12.2024008164240054-122.11.2024
27.12.2024008164240054-122.11.2024
27.12.2024008164240054-122.11.2024
27.12.2024008164240054-122.11.2024
30.12.2024008164240054-122.11.2024
30.12.2024008164240054-122.11.2024
30.12.2024008164240054-122.11.2024
30.12.2024008164240054-122.11.2024
30.12.2024008164240054-122.11.2024
30.12.2024008164240054-122.11.2024
30.12.2024008164240054-122.11.2024

 

Calendar


DateYearMonthMonth NameDay
22.11.202420242024-11Nov 202422
23.11.202420242024-11Nov 202423
24.11.202420242024-11Nov 202424
25.11.202420242024-11Nov 202425
26.11.202420242024-11Nov 202426
27.11.202420242024-11Nov 202427
28.11.202420242024-11Nov 202428
29.11.202420242024-11Nov 202429
30.11.202420242024-11Nov 202430
01.12.202420242024-12Dec 20241
02.12.202420242024-12Dec 20242
03.12.202420242024-12Dec 20243
04.12.202420242024-12Dec 20244
05.12.202420242024-12Dec 20245
06.12.202420242024-12Dec 20246
07.12.202420242024-12Dec 20247
08.12.202420242024-12Dec 20248
09.12.202420242024-12Dec 20249
10.12.202420242024-12Dec 202410
11.12.202420242024-12Dec 202411
12.12.202420242024-12Dec 202412
13.12.202420242024-12Dec 202413
14.12.202420242024-12Dec 202414
15.12.202420242024-12Dec 202415
16.12.202420242024-12Dec 202416
17.12.202420242024-12Dec 202417
18.12.202420242024-12Dec 202418
19.12.202420242024-12Dec 202419
20.12.202420242024-12Dec 202420
21.12.202420242024-12Dec 202421
22.12.202420242024-12Dec 202422
23.12.202420242024-12Dec 202423
24.12.202420242024-12Dec 202424
25.12.202420242024-12Dec 202425
26.12.202420242024-12Dec 202426
27.12.202420242024-12Dec 202427
28.12.202420242024-12Dec 202428
29.12.202420242024-12Dec 202429
30.12.202420242024-12Dec 202430

Hi,

sorry, I posted the test data in my original post.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors