Forum Discussion
Mohan128256
2 years agoHelper IV
Need help in optimizing DAX query
Hello All, I have written below dax which is taking 30+ sec of time to execute and produce the results. _InventoryAmtConversed =
VAR _Onhand_StdCost =
CALCULATE(SUM('Inventory Snapshots'[O...
Mohan128256
2 years agoHelper IV
Greg_Deckler AlexisOlson
I think i did made it more effeciant with what you guys have suggested.
Now the query is running in less than a sec.
here is it
VAR _Table = CALCULATETABLE( 'Inventory Snapshots', KEEPFILTERS('Inventory Snapshots'[Snapshot Weekly?] = "Y"), KEEPFILTERS('Calendar'[445 Year Week Offset]=0))
VAR _Onhand_StdCost = SUMX( _Table, [On-hand StdCost$])
VAR _PickedQty = SUMX( _Table, [Picked Qty])
VAR _currency = MAX( 'Inventory Snapshots'[Currency]) --USD
VAR _currencySelected =
MAXX(ALLSELECTED('Exchange Rates'[To Currency]), 'Exchange Rates'[To Currency])
VAR _ConversationRate =
LOOKUPVALUE (
'Exchange Rates'[Exchange Rate],
'Exchange Rates'[To Currency], _currencySelected
,'Exchange Rates'[From Currency],"USD"
)*1
RETURN
IF(_currencySelected = "USD",(_Onhand_StdCost+_PickedQty),
(_Onhand_StdCost+_PickedQty*_ConversationRate))
As i said the culprit was switch...but before that i see it was having major concern at selectedvalue of to currency.
So i did change it to
VAR _currencySelected =
MAXX(ALLSELECTED('Exchange Rates'[To Currency]), 'Exchange Rates'[To Currency])
And We have USD value also in To Currency which should get multiplied by 1, So i tried to avoid that condition by making it into a final switch case with less condition.
VAR _ConversationRate =
LOOKUPVALUE (
'Exchange Rates'[Exchange Rate],
'Exchange Rates'[To Currency], _currencySelected
,'Exchange Rates'[From Currency],"USD"
)*1
RETURN
IF(_currencySelected = "USD",(_Onhand_StdCost+_PickedQty),
(_Onhand_StdCost+_PickedQty*_ConversationRate))
Greg_Deckler You are my guardian angel whenever i get struck with these sort of situations. You always comes to rescue me. Keep doing what you are doing. ❤️
Thanks.
Mohan V.
- Greg_Deckler2 years agoCommunity Champion
Mohan128256 Happy to help!. Wow, that's a pretty dramatic speed improvement from 30 seconds to under a second!