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.
Totally new to Power BI and just can't get my head around this !!
I want to create a Measure that uses an if statement in my Model Table. I can write the if statement ok I just want to return a combination of a field on my table and text.
Solved! Go to Solution.
figured this out. I created a new column within the data environment and used the following syntax (which I guess was the problem all along !!.
figured this out. I created a new column within the data environment and used the following syntax (which I guess was the problem all along !!.
Hi Nate
I tried your suggestion with a test using the following:
if [Field1] = "OK" then "OK" else "Error -"& ([Field2])
Field1 is a calculation returning text "OK"
Field2 is a numerical value
This still has an orange "error" where the condition is not met with the Expression error:
Expression.Error: We cannot apply operator & to types Text and Number.
So then I tried to concatenate like so:
if [Field1] = "OK" then "OK" else "Error -"&Number.ToText([Field2])
Now I get "Error -1" but it isn't yellow and does not link to an explanation.
Any ideas?
You don't need all the parentheses. Just try this:
Measure = if [Field1] = 0 then "OK" else "Error -"& [Field2]
--Nate
Hi there Vera
I figured out that I should be doing this in query (which I have made progress with however I still can't get my formula to concatenate data with text.
My formula is fine until I try to concatenate:
if [#"Trunks & Radials (RPE).RPE Plan"]=[#"Loads (Driver Vehicle).Planned_Total_RPE"] then "OK"
else "Check - "&Text.From[#"Trunks & Radials (RPE).RPE Plan"]&" vs "&Text.From[#"Loads (Driver Vehicle).Planned_Total_RPE"]
The "OK" is present where the condition is met but there is an error where the condition is not met:
(If I use text ("OK" and "Not OK") for both then it works, however I need to concatenate data to create information for the viewer.)
The error message states:
Expression.Error: We cannot apply field access to the type Function.
Details:
Value=[Function]
Key=Trunks & Radials (RPE).RPE Plan
Thanks for your help and patience in advance.
Hi @Anonymous
What error did you get? It is better to provide some sample data...if it is a measure, you can't call a field directly...
Hi @Anonymous
So it is a column, you missed () for the Text.From, but your error was not about it, the question is how you put your if statement? Did you add a custom column in Power Query Editor then put it like this?
if [#"Trunks & Radials (RPE).RPE Plan"]=[#"Loads (Driver Vehicle).Planned_Total_RPE"] then "OK"
else "Check - "&Text.From([#"Trunks & Radials (RPE).RPE Plan"])&" vs "&Text.From([#"Loads (Driver Vehicle).Planned_Total_RPE"])
User | Count |
---|---|
9 | |
8 | |
6 | |
6 | |
6 |