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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Turn multiple names in a column into one name if it matches a list of names

So I have a table with a column that lists multiple names in each row. Only one name in each row is relevant. I want to get rid of the other names, based on a list of names I have stored elsewhere.

So:

NamesValue
Joe, Clara, Sharonx
Kelly, Clara, John, Barbaray
Jacob, Kellyz


I only care about Joe and Kelly, so what I would want to see is:

NamesValue
Joex
Kellyy
Kellyz


I don't know if I need to change the query or do a calculated column or something else. I tried splitting the columns and creating a new column but I've got a lot of data and a long list of names I want to pull from that names column. I'd rather not list out the several dozen names that should be checked for in each of the 4 newly created columns. Is there a relatively simple way to tackle this?

1 ACCEPTED SOLUTION

@Anonymous IDNumber is not correc,t you want [Value]

Agent =
VAR __NamesICareAbout = ALL(Agents[Name])
VAR __Text = SUBSTITUTE([Assigned To],",","|")
VAR __Count = PATHLENGTH(__Text)
VAR __Table =
FILTER(
ADDCOLUMNS(
GENERATESERIES(1,__Count,1),
"__Name",
PATHITEM(__Text,[Value])
),
[__Name] IN __NamesICareAbout
)
 
RETURN
CONCATENATEX(__Table,[__Name],";")

You are using the "index" created by GENERATESERIES to pull the correct path item out of the text path. GENERATESERIES creates a single column table with the column name "Value".



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

If I understand it correctly, you can keep the data simple and clean, here is one way in M. Not sure if you will have Joe and Kelly in the same list, so use list, you can add more names if you care someone else other than Joe and Kelly

 

Vera_33_0-1632363691893.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8spP1VFwzkksStRRCM5ILMrPU9JRqlCK1YlW8k7NyamES3rlZ+TpKDglFiUBuUA1lWA1XonJ+Uk6CmClQMEqpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Names = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Names", type text}, {"Value", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "newName", each List.Select(Text.Split([Names],", "), each List.Contains({"Joe","Kelly"}, _))),
    #"Expanded newName" = Table.ExpandListColumn(#"Added Custom", "newName")
in
    #"Expanded newName"

 

Greg_Deckler
Super User
Super User

@Anonymous One way:

Column = 
  VAR __NamesICareAbout = SELECTCOLUMNS('PeopeWhoMatter'[Names])
  VAR __Text = SUBSTITUE([Names],", ","|")
  VAR __Count = PATHLENGTH(__Text)
  VAR __Table = 
    FILTER(
      ADDCOLUMNS(
        GENERATESERIES(1,__Count,1),
        "__Name",PATHITEM(__Text,[Value])
      ),
      [__Name] IN __NamesICareAbout
    )
RETURN
  CONCATENATEX(__Table,[__Name],", ")


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler Soooo DAX is all I'm comfortable with, so I tried your solution. This is what I input:


Agent =
VAR __NamesICareAbout = ALL(Agents[Name])
VAR __Text = SUBSTITUTE([Assigned To],",","|")
VAR __Count = PATHLENGTH(__Text)
VAR __Table =
FILTER(
ADDCOLUMNS(
GENERATESERIES(1,__Count,1),
"__Name",
PATHITEM(__Text,[IDNumber])
),
[__Name] IN __NamesICareAbout
)
 
RETURN
CONCATENATEX(__Table,[__Name],";")

The error I get is that "The result of a conversion or arithmetic operation is either too large or too small."
Not sure what that means.

 

@Anonymous IDNumber is not correc,t you want [Value]

Agent =
VAR __NamesICareAbout = ALL(Agents[Name])
VAR __Text = SUBSTITUTE([Assigned To],",","|")
VAR __Count = PATHLENGTH(__Text)
VAR __Table =
FILTER(
ADDCOLUMNS(
GENERATESERIES(1,__Count,1),
"__Name",
PATHITEM(__Text,[Value])
),
[__Name] IN __NamesICareAbout
)
 
RETURN
CONCATENATEX(__Table,[__Name],";")

You are using the "index" created by GENERATESERIES to pull the correct path item out of the text path. GENERATESERIES creates a single column table with the column name "Value".



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.