SWITCH Optimization

Hi, it is a simple code with SWITCH statement, but I had to add extra groups and then everything slowed down. How could I optimize this?

test_New Price =

VAR vPurchase_price_EUR = CALCULATE(SUM(Invent[EstCostPrice])*[Currency ratio Value])

RETURN
SWITCH(TRUE(),

– pricing

SELECTEDVALUE(Invent[GroupId]) = "101",
DIVIDE(vPurchase_price_EUR,(1-0.80)),

SELECTEDVALUE(Invent[GroupId]) = "102",
DIVIDE(vPurchase_price_EUR,(1-0.70)),

SELECTEDVALUE(Invent[GroupId]) = "103",
DIVIDE(vPurchase_price_EUR,(1-0.55)),

SELECTEDVALUE(Invent[GroupId]) = "104",
DIVIDE(vPurchase_price_EUR,(1-0.90)),

SELECTEDVALUE(Invent[GroupId])= "105",
DIVIDE(vPurchase_price_EUR,(1-0.35)),

SELECTEDVALUE(Invent[GroupId]) = "190",
DIVIDE(vPurchase_price_EUR,(1-0.25)),

SELECTEDVALUE(Invent[GroupId])= "195",
DIVIDE(vPurchase_price_EUR,(1-0.60)),

SELECTEDVALUE(Invent[GroupId]) = "198",
DIVIDE(vPurchase_price_EUR,(1-0.60)),

–SONY

SELECTEDVALUE(Invent[GroupId]) = “211” && SELECTEDVALUE(Invent[Brand])=“Sony”,
DIVIDE(vPurchase_price_EUR,(1-0.80)),

SELECTEDVALUE(Invent[GroupId]) = “211” ,
DIVIDE(vPurchase_price_EUR,(1-0.30)),

–ELSE // All other
DIVIDE(vPurchase_price_EUR,(1-0.50)))

Hi @Vladas,

Its very difficult to optimize a dax measure by just looking at it. you have to provide more context to the calculation as why are you writing such a long expression and what is the end goal you want to achieve. Further for optimization purpose a mock up of your existing model is important and also if you can share the vpax file of your model probably then we can think of helping you in terms of optimization.

Regards,
Hemant

2 Likes

Hi @Vladas, we aim to consistently improve the topics being posted on the forum to help you in getting a strong solution faster. While waiting for a response, here are some tips so you can get the most out of the forum and other Enterprise DNA resources.

  • Use the forum search to discover if your query has been asked before by another member.

  • When posting a topic with formula make sure that it is correctly formatted to preformatted text </>.
    image

  • Use the proper category that best describes your topic

  • Provide as much context to a question as possible.

  • Include the masked demo pbix file, images of the entire scenario you are dealing with, screenshot of the data model, details of how you want to visualize a result, and any other supporting links and details.

I also suggest that you check the forum guideline https://forum.enterprisedna.co/t/how-to-use-the-enterprise-dna-support-forum/3951. Not adhering to it may sometimes cause delay in getting an answer.

Please also check the How To Mask Sensitive Data thread for some tips on how to mask your pbix file.

Hi @Vladas, we’ve noticed that no response has been received from you since the 18th of November. We just want to check if you still need further help with this post? In case there won’t be any activity on it in the next few days, we’ll be tagging this post as Solved. If you have a follow question or concern related to this topic, please remove the Solution tag first by clicking the three dots beside Reply and then untick the checkbox. Thanks!