Forum Discussion
Tips for solving a Business Case - INVENTORY ALLOCATION TO CUSTOMER DEMAND
Hello, i need to solve the following Business Case:
i have a Supply - Inventory Table and Demand - Customer Table
I need to create a PBI model to solve the allocation problem between Demand And Supply, below an Excel Example. I would like to undestand how to create a Measure or calculated Column to create the OUTPUT Table Below.
Thank you
- Anonymous2 years ago
Hi NewNow ,
Of course, it is possible to improve the column definitions for calculations by using variables instead of EARLIER functions.
For exampleSubcategory Sales Rank = COUNTROWS( FILTER( Subcategory, EARLIER(Subcategory[Subcategory Sales]) < Subcategory[Subcategory Sales] ) ) + 1The CurrentSubcategorySales variable stores the Subcategory Sales column value in the current row context, and the RETURN expression uses it in the modified filter context.
Subcategory Sales Rank = VAR CurrentSubcategorySales = Subcategory[Subcategory Sales] RETURN COUNTROWS( FILTER( Subcategory, CurrentSubcategorySales < Subcategory[Subcategory Sales] ) ) + 1More details can be found in the documentation:Use variables to improve your DAX formulas - DAX | Microsoft Learn.
Best Regards,
Clara Gong
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 Replies
- NewNowNew Member
I forgot to mention that this scenario it's just for 1 sku (1 SKU with multiple Inventory storage point and with multiple Customer Demand).
In the Scenario i'm trying to solve i have multiple SKU, each one with with multiple Inventory storage point and with multiple Customer Demand
- AnonymousNot applicable
Hi NewNow ,
I create two tables as you mentioned.
Then I create a table and try to use three calculated columns.
value = var _maxindex= MAXX( FILTER(ALL('Output'),'Output'[Inventory Name]=EARLIER('Output'[Inventory Name])),[Index]) RETURN IF( _maxindex<>'Output'[Index], SUMX( FILTER(ALL('Table2'),'Table2'[Customer Name]=EARLIER('Output'[Customer Name])),[Damand QTY]), SUMX( FILTER(ALL('Table1'),'Table1'[Inventory Name]=EARLIER('Output'[Inventory Name])),'Table1'[Avalaible]))Test1 = var _minvalue= MINX( FILTER(ALL('Output'), 'Output'[IF]=1),[Index]) return IF( [Index]<_minvalue, [value] - SUMX(FILTER(ALL('Output'),'Output'[Index]=EARLIER('Output'[Index])-1),[value]),[value])Can you tell me any logic about how to change the DAX codes? I will also do a further research about this topic.
Best Regards,
Clara Gong
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- NewNowNew Member
Hello Anonymous ,
is it possibile to have a solution without the use of the EARLIER function ? Dax guide recomend not to use that one since the introduction of Variables.- AnonymousNot applicable
Hi NewNow ,
Of course, it is possible to improve the column definitions for calculations by using variables instead of EARLIER functions.
For exampleSubcategory Sales Rank = COUNTROWS( FILTER( Subcategory, EARLIER(Subcategory[Subcategory Sales]) < Subcategory[Subcategory Sales] ) ) + 1The CurrentSubcategorySales variable stores the Subcategory Sales column value in the current row context, and the RETURN expression uses it in the modified filter context.
Subcategory Sales Rank = VAR CurrentSubcategorySales = Subcategory[Subcategory Sales] RETURN COUNTROWS( FILTER( Subcategory, CurrentSubcategorySales < Subcategory[Subcategory Sales] ) ) + 1More details can be found in the documentation:Use variables to improve your DAX formulas - DAX | Microsoft Learn.
Best Regards,
Clara Gong
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.