Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
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 Currency Code] = null
then "GBP"
else if GetVar("BU") = "LM" and [Legal Entity] = "aaaaa" then "USD"
else if GetVar("BU") = "LM" and [Legal Entity] = "bbbbb" then "USD"
else if GetVar("BU") = "LM" and [Legal Entity] = "ccccc" then "GBP"
else if GetVar("BU") = "LM" and [Legal Entity] = "ddddd" then "GBP"
else if GetVar("BU") = "LM" and [Payment Currency Code] = null then "USD"
else [Payment Currency Code]
I am wondering if there is a faster way to write this in M code. I mean faster at execution time.
Thank you
Stuart
Solved! Go to Solution.
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.
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.
Thank you to all replies.
Regards
Stuart
calculate GetVar("BU") beforehand
Use List.Contains()
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
12 | |
8 | |
8 | |
7 |
User | Count |
---|---|
15 | |
13 | |
8 | |
7 | |
6 |