Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join 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.

Reply
jwyoung07
New Member

Adding a column label based on text value

Hello, I hope my question is an easy one. I've been poking around the forums and reviewing documentation but can't wrap my head around the best way to do this: I have a list of names for items, and want to label these items based on their name. These items use a naming convention where the beginning of the name indicates what group they belong to. I want to add a column with these groups. Take the data below:

 

jwyoung07_0-1698942373242.png

 

Line 1: the item name begins with 'Red-' so this indicates it belongs in the 'Winners' category. My 'Item Name' is being pulled automatically from a resource. I want to add 'Category' so I can easily splice these items. 

 

I have a feeling it will be a variation of @Greg_Deckler 's solution for Attendance, posted here: Solving Attendance with the Disconnected Table Tri... - Microsoft Fabric Community but can't seem to connect the dots. I'd be happy to provide more info if needed. Thank you!

1 ACCEPTED SOLUTION
jwyoung07
New Member

Update for all: I was able to find a working solution to the problem: a (very long) conditional column: 

 

jwyoung07_0-1698963384010.png

 

The result is a very ugly string of if statements in a single Power Query, but it accomplished exactly what I was trying to do. Thank you!

View solution in original post

4 REPLIES 4
jwyoung07
New Member

Update for all: I was able to find a working solution to the problem: a (very long) conditional column: 

 

jwyoung07_0-1698963384010.png

 

The result is a very ugly string of if statements in a single Power Query, but it accomplished exactly what I was trying to do. Thank you!

mlsx4
Memorable Member
Memorable Member

Hi @jwyoung07 

 

I'm not sure if I have understood it correctly. But, I think you can create a new custom column:

 

Name Category = 

var searchCat = 
LEFT(
    'MyTable'[Item],
    SEARCH(
        "-", 
        MyTable[Item],
        ,
        LEN(MyTable[Item]) + 1
    ) - 1
)

return SWITCH(searchCat,
"Red","Winners",
"Blue","Losers",
"Yellow","Participators",
"Purple","Try-Hards",
"No category")

 

 

mlsx4_0-1698942956097.png

 

I hope it works!

 

Thanks so much for your quick response @mlsx4 ! Pardon my ignorance, but I'm getting a Token Eof error when making this column: 

 

jwyoung07_0-1698944653810.png

 

I'm sure I'm missing something very simple. Please advise, thank you so much!

Hi @jwyoung07 

 

I thought you need it in DAX, so that's why my formula isn't working on M. In M, the solution is the one you has done. I'm glad you finally solved your problem

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.