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
Munawar1881
Helper II
Helper II

Help to Add a new Column with specific Text from other

I need help, please if anyone can provide a sample file that will help me a lot to understand. I have one lots of column but from column "Style Name" which contain description of products with the Gender in it some time genders is places in first some times in middle and some times at end. so cannot use delimeter. 

 

so should I add a column with poer query or dax

 

Style NameGender
KIDS SHOE ASK VELCROKIDS
NATIONAL SHOE ASTRI LOW HE WOMENWOMEN
NATINAL SHOE SONDRE FOR WOMENWOMEN
SANDAL FRIENDS AO FOR KIDSKIDS
SANDAL NP BALI 2 JRKIDS
LADIES CAPRI PANTS 222HP14212 HOUSEWOMEN
W. BLOUSE 213HP14130, HOUSEWOMEN
CHILDREN'S BRIEF 3-PACK 230H071815 HOUSEKIDS
KID S SWIMSUIT 235H032221, RED, 100KIDS
LADIES MAXI JAQUARD AC-, MAITOKAHVIWOMEN
LADIES BRIEF 3-PCS AC-NOS-011 ACTUELLEWOMEN
RUNNING MEN´S JACKET ST-MW-SS22-001MEN
NOS SOCKS 3 PK BABY BOYS BLUE 234NOS19 BABY

 

Thank you so much for your help

best regards,

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

wdx223_Daniel_0-1665996683137.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZFRbsMgDIavYuU5mYC06vboEDpoCGSYNKuyHmM32wl2sjldG7VSnwDzWf+Hmeeicy0B2WgAqYOj8TrForyUi3M5FwGziwH9jcnJgY8TWANT7E1g9n+9wStLMbTJwD6mJyRhaBncJ2cCC2C8cJfUu/ArFQZo0DtQcEj31x5bZwg0Diw1YMgESik7yI2SCmwcyTyETi/Q+KUKStYLJmtRPuG0dZ7Vw9e3EGpH0LDlHupqQN2BqoUVO/kqt2vnKsQb4GlOrqfRZUa3VtSsJEtIpi1BCvHEv8dPBwf8GDG1gLoqueJy7NAe3YPXlV91NC14iFQJKXmbR+P941PSGIIL78Dn3x/iFN2ZDJSrfqqIlKqEkNywfmBk/ag7ghqGjqfenKCJJ870I0+t3jAg34A7lqvifP4D", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Style Name" = _t, Gender = _t]),
    Custom1 = Table.AddColumn(
                              Source,
                              "GenderNew",
                              each List.Skip(
                                             {
                                              {{"BABY"},"BABY"},
                                              {{"LADIES","L.","W.","WOMEN"},"WOMEN"},
                                              {{"MEN'S","MEN´S"},"MEN"},
                                              {{"CHILDREN'S","KIDS","JR","KID "},"KIDS"},
                                              {{"BOYS"},"BOYS"}
                                             },
                                             (x)=>not List.Contains(x{0},[Style Name],(x,y)=>Text.Contains(y,x,Comparer.OrdinalIgnoreCase))
                                            ){0}?{1}? ??"OTHERS")
in
    Custom1

you can update the list in the first parameter of List.Zip

{{the list of text which you want to category to group 1},"group1"},{the list of text which you want to category to group 2},"group2"}.......as many as you want}

 

View solution in original post

1 REPLY 1
wdx223_Daniel
Super User
Super User

wdx223_Daniel_0-1665996683137.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZFRbsMgDIavYuU5mYC06vboEDpoCGSYNKuyHmM32wl2sjldG7VSnwDzWf+Hmeeicy0B2WgAqYOj8TrForyUi3M5FwGziwH9jcnJgY8TWANT7E1g9n+9wStLMbTJwD6mJyRhaBncJ2cCC2C8cJfUu/ArFQZo0DtQcEj31x5bZwg0Diw1YMgESik7yI2SCmwcyTyETi/Q+KUKStYLJmtRPuG0dZ7Vw9e3EGpH0LDlHupqQN2BqoUVO/kqt2vnKsQb4GlOrqfRZUa3VtSsJEtIpi1BCvHEv8dPBwf8GDG1gLoqueJy7NAe3YPXlV91NC14iFQJKXmbR+P941PSGIIL78Dn3x/iFN2ZDJSrfqqIlKqEkNywfmBk/ag7ghqGjqfenKCJJ870I0+t3jAg34A7lqvifP4D", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Style Name" = _t, Gender = _t]),
    Custom1 = Table.AddColumn(
                              Source,
                              "GenderNew",
                              each List.Skip(
                                             {
                                              {{"BABY"},"BABY"},
                                              {{"LADIES","L.","W.","WOMEN"},"WOMEN"},
                                              {{"MEN'S","MEN´S"},"MEN"},
                                              {{"CHILDREN'S","KIDS","JR","KID "},"KIDS"},
                                              {{"BOYS"},"BOYS"}
                                             },
                                             (x)=>not List.Contains(x{0},[Style Name],(x,y)=>Text.Contains(y,x,Comparer.OrdinalIgnoreCase))
                                            ){0}?{1}? ??"OTHERS")
in
    Custom1

you can update the list in the first parameter of List.Zip

{{the list of text which you want to category to group 1},"group1"},{the list of text which you want to category to group 2},"group2"}.......as many as you want}

 

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.