Forum Discussion
Tips for solving a Business Case - INVENTORY ALLOCATION TO CUSTOMER DEMAND
- 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.
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.
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.
- Anonymous2 years agoNot 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.