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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
biwarrior93
Regular Visitor

assign index based on criteria

Hello, I have a table with the following columns:
ID, Email, Phone 1 and Phone 2.
All the IDs are unique. I need to assign a unique index to each record. However, the records that either have the same Email or the same Phone will get the same index. Records with the same Phone 1 in the Phone 2 column, or the same Phone 2 in the Phone 1 column will also get the same index. I need a way to achieve this in Power Query. I tried different codes in M language but it didn't work out.

3 REPLIES 3
biwarrior93
Regular Visitor

The error was fixed, but the output of the code above is a column that assigns a unique index to each row whether it has similarities with other columns or not.

wdx223_Daniel
Super User
Super User

= let fx=(rcd)=>let a=Record.ToList(rcd) in Text.Combine(List.Transform(List.FirstN(a,2)&List.Sort(List.Skip(a,2)),Text.From),"|"),
grp=Table.Group(YourTableName,Table.ColumnNames(YourTableName),{"n",each _},1,(x,y)=>Value.Compare(fx(x),fx(y)))
in Table.Combine(Table.TransformRows(Table.AddIndexColumn(grp,"idx"),each Table.AddColumn([n],"idx",(x)=>[idx])))

I changed the table name with mine and I get the error below :

Expression. Error: A cyclic reference was encountered during evaluation. 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors