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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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