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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Lutz
Frequent Visitor

DAX measure based itself

Hello everyone,

 

I'm developing a tool to calculate the cost associated with inventory storaged at a 3d supplier. The cost is obtained by multipling the stock of each day by its weight and a fare:

Cost_day = (Stock Qty) * (Weight/piece) * (Fare)

 

However, the 'Stock Qty' that should be used to evaluate this cost is not all inventory available, but some amout. This happens because some stock are held at the site, and the rest should be at the 3d supplier (the latter is used to calculate the cost). This split is given by a parameter set by the user (I called D+?), which will define how much coverage in days should be considered and kept at the site. Another restriction is that, when some amout of stock is moved from the 3d supplier to the site, this amout needs to be a multiple value of its package (i.e. if I need 3 parts, and the package for that material is 4, the transfer must be of 4 parts).

 

The data source I have give me Initial Stock, Dates, Requirement, Invoices and and Pieces by Package. Using SUMX, TOPN and a few other expressions I was able to calculate the Running Stock (Stock + Invoices - Requirement) for each date. Using GENERATESERIES I was able to create the 'D+?' parameter and the 'D+? Requirement' and got the expected results.

 

The problem I'm facing is that the stock that should be transfered from the 3d supplier to the site today depends on the amout of stock that I had yesterday, and so on. I was able to create this model in Excel, and it works fine because I can easily make a reference to the previous row on the same column, but this is not true for PBI. For this to work in Excel, I have adopted the premise that, for the first 'Date' entry for each Material, the Stock at the site will be the 'D+?' stock rounded by Pieces by Package.

 

The mathematical expressions for Excel:

Corrected Requirement (Package):  Roundup( ( ('D+? Requirement' + 'Requirement (Today)' )  - 'Last_day_stock'  ) , 'Pieces by Package' )

Site_Stock_EndOfDay = Last_day_stock + Stock_to_transfered * 'Pieces by Package' - Requirement (Today)

 

The table below shows the expected results. The last columns in red headers are the ones I need help with.

 

DateRequirementRequirement (Package)Running StockRequirement (D+2)Requirement (D+2) (Package)Total Requirement (D+2)Total Requirement (D+2) (Package)Corrected RequirementCorrected Requirement (Package)Site_Stock_EndOfDay3d_Supplier_Stock_EndOfDay
Initial Stock  106      2086
27/03/202162100113174001486
28/03/20215195123174311481
29/03/202162898214300881
30/03/202162831231841021271
31/03/20212181143164411566
01/04/20211027182184311061
02/04/20214167519200661
03/04/20214163519231756

 

I appreciate any help I can get.

 

Thanks!

 

 

 

 

2 REPLIES 2
Lutz
Frequent Visitor

Hi @Anonymous,

 

I didn't develop in Power Query because I need to simulate this for at least 5 different values of 'D+?'. Also, I have at least 10k Materials and Date range needs to be at least 1 year long. Additionally, this PBI will be connected to a live data source, and it will take too long to refresh. 

 

Thanks!

Anonymous
Not applicable

@Lutz 

 

Why don't you calculate this in Power Query? I understand that this calculation should be done in the base tables, so it only makes sense to use PQ. And in there you can easily create calculations which refer to the previous row.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors