Forum Discussion

StuartPQY's avatar
StuartPQY
Frequent Visitor
1 year ago
Solved

Faster M code at execution time for nested if statement

Hello   I have the following code in a nested if statment format   if GetVar("BU") = "UK" and [Cost Centre] >= 17000 and [Cost Centre] < 10826 then "EUR" else if GetVar("BU") = "UK" and [Payment...
  • Omid_Motamedise's avatar
    1 year ago

    replace your if conditions with the below code

    if GetVar("BU") = "UK" then
        if [Cost Centre] >= 17000 and [Cost Centre] < 10826 then "EUR"
        else if [Payment Currency Code] = null then "GBP"
        else [Payment Currency Code]
    else if GetVar("BU") = "LM" then
        if [Legal Entity] = "aaaaa" or [Legal Entity] = "bbbbb" then "USD"
        else if [Legal Entity] = "ccccc" or [Legal Entity] = "ddddd" then "GBP"
        else if [Payment Currency Code] = null then "USD"
        else [Payment Currency Code]
    else 
        [Payment Currency Code]

     

     

    in the if using and/or  will evaluate every time but replaced them by a nested if can increase the efficiency.

     

    another tips which is related to the data structure, use the condition wich can filter more rows in the first condition series.