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
How can we create measure or column in power bi with case statement as below.
Select column 1,column2,
CASE
WHEN a.appt = 1
THEN 0
ELSE 1
END AS Column3
From table 1
where Condition = 'stop'
Thanks in Advance
Solved! Go to Solution.
If there are just two conditions, use the IF() function. If there will be more, use the SWITCH() function. If you have multiple things to test for each condition, you can either use AND() for 2 items, or && for multiple items. For example:
=IF([Item1] > 100 && [Item2] <> 1 && [Item3] = "Garage", Do this, else do that.)
That will only "do this" if all 3 condtions are true. Otherwise it does the else part, or "else do that"
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI Reporting
@Anonymous wrote:This is the error i am getting while using IF() function
Column = IF(table1[appt]="1" && table1[condition]="stop" && table1[condition]="0",0,1)
Errot: DAX comparison operations do not support comparing values of type Integer with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values.
If [appt] and [condition] are values, then you need to compare as values, not text. So try:
Column = IF(table1[appt]=1 && table1[condition]="stop" && table1[condition]=0,0,1)
Your comparison type needs to match the data type. Dates to dates, text to text, numbers to numbers, boolean/logical to boolean. DAX is very strict here. You cannot get away with comparing 1 to "1" and getting a match. Not only will it not match, it returns the error you got.
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingIf there are just two conditions, use the IF() function. If there will be more, use the SWITCH() function. If you have multiple things to test for each condition, you can either use AND() for 2 items, or && for multiple items. For example:
=IF([Item1] > 100 && [Item2] <> 1 && [Item3] = "Garage", Do this, else do that.)
That will only "do this" if all 3 condtions are true. Otherwise it does the else part, or "else do that"
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingThis is the error i am getting while using IF() function
Errot: DAX comparison operations do not support comparing values of type Integer with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values.
@Anonymous wrote:This is the error i am getting while using IF() function
Column = IF(table1[appt]="1" && table1[condition]="stop" && table1[condition]="0",0,1)
Errot: DAX comparison operations do not support comparing values of type Integer with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values.
If [appt] and [condition] are values, then you need to compare as values, not text. So try:
Column = IF(table1[appt]=1 && table1[condition]="stop" && table1[condition]=0,0,1)
Your comparison type needs to match the data type. Dates to dates, text to text, numbers to numbers, boolean/logical to boolean. DAX is very strict here. You cannot get away with comparing 1 to "1" and getting a match. Not only will it not match, it returns the error you got.
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingCovering 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 |
---|---|
111 | |
100 | |
80 | |
64 | |
58 |
User | Count |
---|---|
148 | |
111 | |
93 | |
84 | |
66 |