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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Looping through rows to find the largest link

Hello everyone, need your help browsing the lines to find the longest link. Indeed, for each letter in the Parent column, I try to iterate over the Link column, to get the common letter among the links (length > 1) (here "A" for the first row) then output the largest link containing this common letter. The Output column is my expected output. I tried to create a function to get the links containing the parent letter, and another to get the longest link. But no success.

I'm still new to Power Query so thank you and sorry in advance if I ask lots of follow up questions. I am enclosing a link to the file. 

https://docs.google.com/spreadsheets/d/1NrlacnkYvXlDvpF0hhmP2QM7x9zrZYUK/edit?usp=sharing&ouid=10524... 

Many thanks,

Gop01

Capture d'écran_20221204_182857.png

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your description, here's my solution.

1. Create a custom column.

Length = Text.Length([Link])

2. Create another custom column.

Output = let 
T=Table.SelectRows(#"Added Custom1",(x)=>Text.Start(x[Link],1)=Text.Start([Link],1))
in 
Table.SelectRows(#"Added Custom1",(x)=>Text.Start(x[Link],1)=Text.Start([Link],1)and x[Length]=List.Max(T[Length]))[Link]{0}

Get the correct result:

vkalyjmsft_0-1670316409458.png

Here's the whole M syntax:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXIC4oAgfxcg5eikFKsDEXVGEnUGi4JEXJDVOruAxZ3QVDs5ww0JRRIOBYuCmJ6ohnjCTYEgqCPC4AJhWPnOSBqc4WbDRSBuC0UIQez3RFGDzepYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Parent = _t, Child = _t, Param = _t, Link = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Parent", type text}, {"Child", type text}, {"Param", type text}, {"Link", type text}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "Length", each Text.Length([Link])),
    #"Added Custom" = Table.AddColumn(#"Added Custom1", "Output", each let T=Table.SelectRows(#"Added Custom1",(x)=>Text.Start(x[Link],1)=Text.Start([Link],1))
     in 
     Table.SelectRows(#"Added Custom1",(x)=>Text.Start(x[Link],1)=Text.Start([Link],1)and x[Length]=List.Max(T[Length]))[Link]{0}),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Length"})
in
    #"Removed Columns"

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your description, here's my solution.

1. Create a custom column.

Length = Text.Length([Link])

2. Create another custom column.

Output = let 
T=Table.SelectRows(#"Added Custom1",(x)=>Text.Start(x[Link],1)=Text.Start([Link],1))
in 
Table.SelectRows(#"Added Custom1",(x)=>Text.Start(x[Link],1)=Text.Start([Link],1)and x[Length]=List.Max(T[Length]))[Link]{0}

Get the correct result:

vkalyjmsft_0-1670316409458.png

Here's the whole M syntax:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXIC4oAgfxcg5eikFKsDEXVGEnUGi4JEXJDVOruAxZ3QVDs5ww0JRRIOBYuCmJ6ohnjCTYEgqCPC4AJhWPnOSBqc4WbDRSBuC0UIQez3RFGDzepYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Parent = _t, Child = _t, Param = _t, Link = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Parent", type text}, {"Child", type text}, {"Param", type text}, {"Link", type text}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "Length", each Text.Length([Link])),
    #"Added Custom" = Table.AddColumn(#"Added Custom1", "Output", each let T=Table.SelectRows(#"Added Custom1",(x)=>Text.Start(x[Link],1)=Text.Start([Link],1))
     in 
     Table.SelectRows(#"Added Custom1",(x)=>Text.Start(x[Link],1)=Text.Start([Link],1)and x[Length]=List.Max(T[Length]))[Link]{0}),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Length"})
in
    #"Removed Columns"

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

It works ! thank you 

jbwtp
Memorable Member
Memorable Member

hi @Anonymous,

 

Something like this?

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUSosKkotUorVgfAcg13g7GBHMNMJyEwsTkkrTkxJS0+DCzkGO7kgcVz8vD2cnJRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Parent = _t, Link = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Parent", type text}, {"Link", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Parent"}, {{"Longest", (x)=> List.First(List.Sort(List.Select(x[Link], each Text.Contains(_, x[Parent]{0})), (x,y)=> if Text.Length(x) < Text.Length (y) then 1 else 0)) }}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Parent"}, #"Grouped Rows",  {"Parent"}, "Grouped Rows", JoinKind.LeftOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"Longest"}, {"Longest"})
in
    #"Expanded Grouped Rows"
Anonymous
Not applicable

not excatly but thank you for your help .

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.