Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi all,
I'd like to use an if statement in the power bi query editor to choose what lines of m-language code to execute based on a certain variable:
For example:
if myVariable = 0 then #"Expanded {0}" = Table.ExpandRecordColumn(#"aaaa", "Column1", {"id", "name", "type"}, {"id", "name", "type"}), #"Expanded {0}1" = Table.ExpandListColumn(#"Expanded {0}", "type") in #"Expanded {0}1" else #"Expanded {0}" = Table.ExpandRecordColumn(#"bbbb", "Column1", {"id", "name", "type"}, {"id", "name", "type"}), #"Expanded {0}1" = Table.ExpandListColumn(#"Expanded {0}", "type") in #"Expanded {0}1"
is it possible somehow? I seem it doesn't
Thanks a lot in advance for any hint
Solved! Go to Solution.
Yes, you're already there: Just add some let-expressions. This is the pattern:
let myVariable = 1, Result = if myVariable = 1 then let DoSth = "DoSth", DoSthElse = "myVariable is 1" in DoSthElse else let ElseDoSth = "Here is my else", Else2DoSth = "Here is my other else" in Else2DoSth in Result
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Yes, you're already there: Just add some let-expressions. This is the pattern:
let myVariable = 1, Result = if myVariable = 1 then let DoSth = "DoSth", DoSthElse = "myVariable is 1" in DoSthElse else let ElseDoSth = "Here is my else", Else2DoSth = "Here is my other else" in Else2DoSth in Result
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
96 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
102 | |
88 | |
63 |