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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply

FIFO

Hi All 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.  

 

Any suggestion of fomula to get the beblow result?

 

Thanks and Regards,

 

Sales Table

DateProduct NameQuantity
10/10/2022A10
10/12/2022A3
10/12/2022A2
10/13/2022A1
10/10/2022B22
10/11/2022B10
10/12/2022B3
10/12/2022B3

 

Purchase Table

DateProduct NameQuantityCost
9/12/2022A10110
9/30/2022A4130
10/1/2022A6150
9/1/2022B20210
9/2/2022B20250
9/20/2022B10230

 

Then i would like get the table like this;

 

DateProduct NameQuantity

Cost of sales

Closing Inventory Qty

Closing Inventory Value

10/10/2022A101100101420
10/12/2022A339071030
10/12/2022A22805750
10/13/2022A11504600
10/10/2022B224700286800
10/11/2022B102500184300
10/12/2022B3750153550
10/12/2022B3750122800
4 REPLIES 4
pi_eye
Resolver IV
Resolver IV

Hi 

Hi PhyuLayKhine333,

Please see .pbix https://drive.google.com/file/d/1WZ1oCP-BtqSxu8t672K1OyTCqUlEdNZv/view?usp=sharing

I was able to achieve this in Power query with a number of steps. Basically we to work out the cumulative number of units sold, and purchase for each product. Then we take that and make a range.

 

EG for products purchased, I_From and I_To are the cumulative range of total #items 

pi_eye_0-1665760726796.png

 

We do the same for the stock being sold. What we can then do is compare those ranges.

So for the 4 units of stock bought at 130 - any stock we sell will between the 11th and 14th items sold.

 

Those two tables can then be merged and filtered to retrieve only the matching rows where there is overlap between these ranges. These overlaps can then be priced as per the purchased table.

 

This table can be further refined and CoGS added:

pi_eye_1-1665760929169.png

 

 

Let me know if you can access the .pbix. There are a lot of steps!

 

Pi

 

 

 

 

Thank you so much for your precious reply and also provide the files. But one of my questions is that the Product A numbers are accurate. But the numbers for Product B are wrong . My data include multiple products and multiple sales and purchase transactions per day . Could you please give me the suggestion about how to correct the Product B 's Cost of Sales. 

Thanks and Regards,

 

 

asking.png

 

Also ,I can access .pbix。

Thank you, I will take a look later. It could also be that I copied the initial data wrong but will take alook.

For the first product A , it got the correct answer . But , for the products below Product A got the wrong answer . 

I have Multiple products , Multiple date and will have duplicate quantity and sale transactions for the same day . I am afraid that duplicate quantity will not display correctly. 

 

Thank you and Looking forward to your reply. 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.