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.
Hello everyone, I'm trying to create a calculated column to add a description to a column of codes you already have.
I tried something like this:
Commodity Code Desc = var x = [table_code]
return IF( x = VALUE(CONTAINSSTRING(table[table_code]; "M01")); "Dec 1";
IF( x = VALUE(CONTAINSSTRING(table[table_code];" M02"); "Dic2";
IF(x = VALUE(CONTAINSSTRING(table[table_code]; "M03")); "Dec 3";
IF(x = VALUE(CONTAINSSTRING(table[table_code]; "M04")); "Dec 4";
IF( x = VALUE(CONTAINSSTRING(table[table_code]; "S02")); "Desc 5" ;
IF(x = VALUE(CONTAINSSTRING(table[table_code];" MBL")); "Dec 6";
IF( x =VALUE(CONTAINSSTRING(table[table_code];" MVA")); "Desc 7"; "General")))))))))
But this is the message I get from Power Bi
"DAX comparison operations do not support comparing Text values to values of type Number. Consider using the VALUE or FORMAT function to convert one of the values."
I used CONTAINSSTRING because I have many records and I have to follow the logic to add the correct description depending on how each of my codes starts.
Do you guys have any other ideas? Thank you very much for your help
Solved! Go to Solution.
CONTAINSSTRING returns true or false. VALUE converts a text string that represents a number to a number. So that's why the error results.
If you want to use the technique (using a switch instead of the IFs, the code will probably look like:
Commodity Code Desc =
SWITCH (TRUE(),
CONTAINSSTRING(Table[table_code], "M01"), "Dec 1",
CONTAINSSTRING(Table[table_code], " M02"), "Dic2",
CONTAINSSTRING(table[table_code], "M03"), "Dec 3",
CONTAINSSTRING(table[table_code], "M04"), "Dec 4",
CONTAINSSTRING(table[table_code], "S02"), "Desc 5" ,
CONTAINSSTRING(table[table_code]," MBL"), "Dec 6",
CONTAINSSTRING(table[table_code]," MVA"), "Desc 7", "General")
If all the table_code fields have the 3 letter code on the left, you might use LEFT( thefield , 3). Good luck.
CONTAINSSTRING returns true or false. VALUE converts a text string that represents a number to a number. So that's why the error results.
If you want to use the technique (using a switch instead of the IFs, the code will probably look like:
Commodity Code Desc =
SWITCH (TRUE(),
CONTAINSSTRING(Table[table_code], "M01"), "Dec 1",
CONTAINSSTRING(Table[table_code], " M02"), "Dic2",
CONTAINSSTRING(table[table_code], "M03"), "Dec 3",
CONTAINSSTRING(table[table_code], "M04"), "Dec 4",
CONTAINSSTRING(table[table_code], "S02"), "Desc 5" ,
CONTAINSSTRING(table[table_code]," MBL"), "Dec 6",
CONTAINSSTRING(table[table_code]," MVA"), "Desc 7", "General")
If all the table_code fields have the 3 letter code on the left, you might use LEFT( thefield , 3). Good luck.
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 |
---|---|
113 | |
99 | |
80 | |
70 | |
59 |
User | Count |
---|---|
149 | |
114 | |
107 | |
89 | |
67 |