Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi,
I'm looking to create a column that will display new text values. Below is the formula I've been using so far, but looking for something that would work using CONTAINS not EQUAL as there are over 2,000 distinct values. So, for example, if the text contains organic then return "Organic" if paid return "Paid".
Solved! Go to Solution.
You can use the DAX function SWITCH along with the CONTAINS function to check if the text field contains certain values and return different text based on the result.
Here is an example of how you can modify your formula to achieve this:
Column = SWITCH(
TRUE(),
CONTAINS('External Traffic'[Source Medium], "google / organic"), "Organic",
CONTAINS('External Traffic'[Source Medium], "Facebook / Paid"), "Paid",
"Other"
)
This formula will check if the Source Medium field contains the string "google / organic" and return "Organic" if it does, then it will check if it contains the string "Facebook / Paid" and return "Paid" if it does, and finally it will return "Other" if none of the previous conditions are met.
You can use the DAX function SWITCH along with the CONTAINS function to check if the text field contains certain values and return different text based on the result.
Here is an example of how you can modify your formula to achieve this:
Column = SWITCH(
TRUE(),
CONTAINS('External Traffic'[Source Medium], "google / organic"), "Organic",
CONTAINS('External Traffic'[Source Medium], "Facebook / Paid"), "Paid",
"Other"
)
This formula will check if the Source Medium field contains the string "google / organic" and return "Organic" if it does, then it will check if it contains the string "Facebook / Paid" and return "Paid" if it does, and finally it will return "Other" if none of the previous conditions are met.
Hey @AlbertS071,
You can use the SWITCH function to more easily handle multiple IF conditions at once. For the contains condition, use the CONTAINSSTRING function. For instance:
Column =
SWITCH (
TRUE,
CONTAINSSTRING ( 'External Traffic'[Source Medium], "google / organic" ), "Organic",
CONTAINSSTRING ( 'External Traffic'[Source Medium], "Facebook / Paid" ), "Paid",
"Other"
)
Hi @AlbertS071 ,
Try using CONTAINS() or CONTAINSSTRING().
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel
Proud to be a Super User!
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
25 | |
13 | |
11 | |
9 | |
6 |