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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply

FIFO Cost of Sales and Closing Inventory Calculation

Hi All BI Experts,

 

I am beginner to BI and tried many methods in order to get the below result and also google about this problem but i did not get the correct answer and have no ideas how to use the relevant formula to get this below result.  The calculation is about if the current cummulative sale qty with the current product name is less than current cummulative purchase qty which is filter by date , then using the current number . If not, then using another row quantity . Its basis is just fifo inventory valuation method. 

 

Any suggestion of fomula to get the beblow result?

 

Thanks and Regards,

 

Sales Table

DateProduct NameQuantity

Cummulative Qty

10/10/2022A1010
10/12/2022A313
10/12/2022A215
10/13/2022A116
10/10/2022B2222
10/11/2022B1032
10/12/22B335

 

Purchase Table

DateProduct NameQuantityCummulative QuantityCost
9/12/2022A1010110
9/30/2022A414130
10/1/2022A620150
9/1/2022B2020210
9/2/2022B2040250
9/20/2022B1050230

 

Then i would like get the table like this;

 

DateProduct NameQuantity

Cummulative Qty

Cost

(only show text like this)

Cost

(show total calculation number)

Closing Inventory Qty

Closing Inventory Value(only show text like this

Closing Inventory Value(show total calculation number)

10/10/2022A1010(110*10)110010(130*4)+(150*6)1420
10/12/2022A313(130*3)3907(130*1)+(150*6)1030
10/12/2022A215(130*1)+(150*1)2805(150*5)750
10/13/2022A116(150*1)1504(150*4)600
10/10/2022B2222(210*20)+(250*2)92028(250*18)+(230*10)6800
10/11/2022B1032(250*10)250018(250*8)+(230*10)4300
10/12/22B335(250*3)75015(250*5)+(230*10)3550
1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @PhyuLayKhine333,

I'd like to suggest you use summarize function to summary table records to calculate the total values in the variable, then you can use the iterator function to aggregate the variable table result to apply second aggregations.

Cumm Cost =
VAR summary =
    SUMMARIZE (
        Purchase,
        [Product Name],
        [Date],
        "Total", [Quantity] * purchase[Cost]
    )
RETURN
    SUMX (
        FILTER (
            summary,
            [Product Name] = EARLIER ( Purchase[Product Name] )
                && [Date] <= EARLIER ( Purchase[Date] )
        ),
        [Total]
    )

Measure Totals, The Final Word 

Regards,

Xiaoxin Sheng

View solution in original post

7 REPLIES 7
KatyaK
New Member

Hi dear, did you solve the task? I have the same problem

amitchandak
Super User
Super User

@PhyuLayKhine333 , if you need a column

 

Cumm Qty = sumx(filter(table, [Product Name] = earlier([Product Name] ) && [Date] <= earlier([Date] ) ),[Quantity])

 

Cumm Cost = sumx(filter(table, [Product Name] = earlier([Product Name] ) && [Date] <= earlier([Date] ) ),[Quantity]*[Cost])


measure without date table

 

Cumm Qty = sumx(filter(allselected(table), [Product Name] = max([Product Name] ) && [Date] <= max([Date] ) ),[Quantity])

 

Cumm Cost = sumx(filter(allselected(table), [Product Name] = max([Product Name] ) && [Date] <= max([Date] ) ),[Quantity]*[Cost])

 

 

example measure with date table, joined with date of your tables

 

Cumm Cost = calculate( sumx(Table,[Quantity]*[Cost]), filter(all(Date), Date[Date]<= Max(Date[DAte])))

Cumm Cost = calculate( sumx(Table,[Quantity]*[Cost]), filter(allselected(Date), Date[Date]<= Max(Date[DAte])))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

sir ,i just want to get each row cost not the cummulative cost.

Sir, I have try your formula and get this result which is not cummulative and only show the total cost of sales for each product and the cost of sales result is not correct . 

I am using 

Cumm Cost = sumx(filter(Purchase, [Product Name] = earlier([Product Name] ) && [Date] <= earlier([Date] ) ),[Quantity]*purchase [Cost]
 

The result;

DateProduct NameQuantityCumm QtyCumm Cost
Monday, October 10, 2022A10102520
Wednesday, October 12, 2022A3152520
Wednesday, October 12, 2022A2152520
Thursday, October 13, 2022A1162520
Monday, October 10, 2022B222211500
Tuesday, October 11, 2022B103211500
Wednesday, October 12, 2022B33511500

 

The result i would like to get;

teProduct NameQuantity

Cummulative Qty

Fifo Cost of sales

 

Closing Inventory Qty

Closing Inventory Value

10/10/2022A10101100101420
10/12/2022A31339071030
10/12/2022A2152805750
10/13/2022A1161504600
10/10/2022B2222920286800
10/11/2022B10322500184300
10/12/22B335750153550

 

Anonymous
Not applicable

HI @PhyuLayKhine333,

I'd like to suggest you use summarize function to summary table records to calculate the total values in the variable, then you can use the iterator function to aggregate the variable table result to apply second aggregations.

Cumm Cost =
VAR summary =
    SUMMARIZE (
        Purchase,
        [Product Name],
        [Date],
        "Total", [Quantity] * purchase[Cost]
    )
RETURN
    SUMX (
        FILTER (
            summary,
            [Product Name] = EARLIER ( Purchase[Product Name] )
                && [Date] <= EARLIER ( Purchase[Date] )
        ),
        [Total]
    )

Measure Totals, The Final Word 

Regards,

Xiaoxin Sheng

 I have 2 tables which is sales and purchase table. Which table name do i need to use for Cumm Cost. 

 

  Cumm Qty = sumx(filter(table, [Product Name] = earlier([Product Name] ) && [Date] <= earlier([Date] ) ),[Quantity])

  Cumm Cost = sumx(filter(table, [Product Name] = earlier([Product Name] ) && [Date] <= earlier([Date] ) ),[Quantity]*[Cost])

 

 

 

Hey @PhyuLayKhine333 Is this solved?

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.