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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Miles1987
Frequent Visitor

Count number of similar elements in columns.

Hello, 

I am having problems solving the issue below

I have a table with these columns, where I am trying to calculate the one called "Wanted result" in PQ. but have not succeeded yet. Basically, I am trying to count how many of the in IDs I column “Employee id” appear in column “Former Employee id “. Without creating more duplicate rows in EOM column.

EOMEmployee idFormer Employee id Wanted result
31. december 2019W00009W000080
31. maj 2020W00062W000621
31. marts 2022W00062,W23166W000621
31. december 2021W00090W000901
31. juli 2021W00090W00090,W219391
31. maj 2021W00090W00091,W255600
31. december 2020W00090W002600
31. januar 2022W00090,W21939W000901
31. juli 2022W00090,W21939W00090,W219392

 

 

Best regards Jesper

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Use below formula

= List.Count(List.Intersect({Text.Split([Former Employee id],","),Text.Split([Employee id],",")}))

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc89DsMgDAXgq0TMKLKNgspJMkQZaMNQVDrQ5P4hyo9RKEyW3ieePQxCYdtM7uXC08WGAI2Qoof0ruEhRrm7YH0iBEeiiQcmcf5tiDPZk0KtS5vVEh6xAR5O55fPu2LS32iUuW9YSkyy6zT8LYcbp8x5+11szC/i1uqmdXotPK4=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [EOM = _t, #"Employee id" = _t, #"Former Employee id" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each List.Count(List.Intersect({Text.Split([Former Employee id],","),Text.Split([Employee id],",")})), Int64.Type)
in
    #"Added Custom"

View solution in original post

1 REPLY 1
Vijay_A_Verma
Super User
Super User

Use below formula

= List.Count(List.Intersect({Text.Split([Former Employee id],","),Text.Split([Employee id],",")}))

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc89DsMgDAXgq0TMKLKNgspJMkQZaMNQVDrQ5P4hyo9RKEyW3ieePQxCYdtM7uXC08WGAI2Qoof0ruEhRrm7YH0iBEeiiQcmcf5tiDPZk0KtS5vVEh6xAR5O55fPu2LS32iUuW9YSkyy6zT8LYcbp8x5+11szC/i1uqmdXotPK4=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [EOM = _t, #"Employee id" = _t, #"Former Employee id" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each List.Count(List.Intersect({Text.Split([Former Employee id],","),Text.Split([Employee id],",")})), Int64.Type)
in
    #"Added Custom"

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.