Forum Discussion
Adding a new column in PowerBI
Hello,
I'm trying to find a way to quickly analyse a column in my table that contains various veriations of the word "voucher" in it and then create a column with a specific description, e.g. "Voucher Issue" in it.
Examples of the data I'm analysing from the [Case_Title] column
| Complaint - voucher |
This is my Power Query statement = Table.AddColumn(#"Changed Type", "Case_Category", each if Text.Contains([Case_title], "Voucher") then "Voucher Issue" else "Other"), it runs, but returns the value of Error in the new columnn.
What am I doing wrong?
Thanks
Thanks, clicking on the Error column gave me insight to the problem! Appreciate the help.
9 Replies
- cengizhanarslanSuper User
Column name is case-sensitive and If any rows have null in Case_Title, Text.Contains will throw an error. Try this instead:
Table.AddColumn( #"Changed Type", "Case_Category", each if [Case_Title] <> null and Text.Contains([Case_Title], "Voucher", Comparer.OrdinalIgnoreCase) then "Voucher Issue" else "Other" ) - ralf_antonResolver I
Hallo,
die Anweisung ist nicht zu beanstanden. Wie lautet denn die Fehlermeldung?
- afaberRegular Visitor
Thanks, I tried that, but it's still returning the word Error in the results of the column.
- afaberRegular Visitor
Thanks, clicking on the Error column gave me insight to the problem! Appreciate the help.
- v-dineshyaCommunity Support
Hi afaber ,
Thank you for reaching out to the Microsoft Community Forum.
If your column contain errors, nulls or unexpected values, Please try below M code to fix the issue.
Table.AddColumn(
#"Changed Type",
"Case_Category",
each
try
if Text.Contains(
Text.From([Case_Title]),
"voucher",
Comparer.OrdinalIgnoreCase
)
then "Voucher Issue"
else "Other"
otherwise "Other",
type text
)Below M code handles nulls and case variations.
= Table.AddColumn(
#"Changed Type",
"Case_Category",
each
if [Case_title] <> null
and Text.Contains([Case_title], "voucher", Comparer.OrdinalIgnoreCase)
then "Voucher Issue"
else "Other",
type text
)I hope this information helps. Please do let us know if you have any further queries.
Regards,
Dinesh
- Ray_MindsSolution Supplier