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

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

Reply
twister8889
Helper V
Helper V

Creating index by group column power query

Hi guys,

 

I need to join two tables by one field, and I would like to do this using one number field, not string.

Table1

IDAttributeValueExpectedIDTable1

StringtoID1

CustomerCustomer11
StringtoID1ProductPrduct11
StringtoID2CustomerCustomer22
StringtoID2ProductProduct22

 

Table2

IDTable1ValueExpectedIDTable1
StringtoID12001
StringtoID23002

 

I need to join Table1 and Table2, but I would like to create a column as number index to replace the "StringtoID" values. How do I do the ExpectedIDTable1 on Table1 and Table2?

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@twister8889 Perhaps:

Table (1)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi4pysxLL8n3dDFU0lFyLi0uyc9NLUJiGirF6qArCyjKTylNLgGzQAx0NUbYjTLCogzZKDALqCgWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Attribute = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Attribute", type text}, {"Value", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Grouped Rows" = Table.Group(#"Added Index", {"ID"}, {{"Min", each List.Min([Index]), type number}, {"Table", each _, type table [ID=nullable text, Attribute=nullable text, Value=nullable text, Index=number]}}),
    #"Added Index1" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type),
    #"Expanded Table" = Table.ExpandTableColumn(#"Added Index1", "Table", {"Attribute", "Value"}, {"Table.Attribute", "Table.Value"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Table",{"Min"})
in
    #"Removed Columns"

 

Table (2)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi4pysxLL8n3dDFU0lEyMjBQitVBFjUCihqDRGMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [IDTable1 = _t, Value = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type)
in
    #"Added Index"

 

 



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
v-kelly-msft
Community Support
Community Support

Hi  @twister8889 ,

 

If all the ID columns are as you show,you could also use below M codes:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi4pysxLL8n3dDFU0lFyLi0uyc9NLUJiGirF6qArCyjKTylNLgGzQAx0NUbYjTLCogzZKDALqCgWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Attribute = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Attribute", type text}, {"Value", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [ID]),
    #"Replaced Value" = Table.ReplaceValue(#"Added Custom","StringtoID"," ",Replacer.ReplaceText,{"Custom"}),
    #"Trimmed Text" = Table.TransformColumns(#"Replaced Value",{{"Custom", Text.Trim, type text}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Trimmed Text",{{"Custom", Int64.Type}})
in
    #"Changed Type1"

And you will see:

vkellymsft_0-1629784470978.png

For the related .pbix file,pls see attached.

 

 

Best Regards,
Kelly

Did I answer your question? Mark my reply as a solution!

 

Greg_Deckler
Community Champion
Community Champion

@twister8889 Perhaps:

Table (1)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi4pysxLL8n3dDFU0lFyLi0uyc9NLUJiGirF6qArCyjKTylNLgGzQAx0NUbYjTLCogzZKDALqCgWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Attribute = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Attribute", type text}, {"Value", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Grouped Rows" = Table.Group(#"Added Index", {"ID"}, {{"Min", each List.Min([Index]), type number}, {"Table", each _, type table [ID=nullable text, Attribute=nullable text, Value=nullable text, Index=number]}}),
    #"Added Index1" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type),
    #"Expanded Table" = Table.ExpandTableColumn(#"Added Index1", "Table", {"Attribute", "Value"}, {"Table.Attribute", "Table.Value"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Table",{"Min"})
in
    #"Removed Columns"

 

Table (2)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi4pysxLL8n3dDFU0lEyMjBQitVBFjUCihqDRGMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [IDTable1 = _t, Value = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type)
in
    #"Added Index"

 

 



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.