It sounds like you're trying to resolve a recursive "replace by" chain in Power Query to determine the final/latest item in the sequence.
This is a common scenario when dealing with product lifecycle or substitution chains. Since Power Query (M) doesn't support true recursion natively, we'll simulate it using a custom function that loops through replacements until it reaches the end of the chain. Here's a way to solve your problem using a custom function and a merge operation:
let
// Load and clean your data
Source = Excel.Workbook(File.Contents("link to your file"), null, true),
ReplaceBy_Sheet = Source{[Item="ReplaceBy",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(ReplaceBy_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Item", type text}, {"Replace By", type text}}),
// Create a function to trace the replacement chain
GetLatest = (startItem as text, table as table) as text =>
let
nextItem = Record.FieldOrDefault(
Table.SelectRows(table, each [Item] = startItem){0}?,
"Replace By",
null
),
result = if nextItem = null or nextItem = "" or nextItem = startItem
then startItem
else @GetLatest(nextItem, table)
in
result,
// Add a column to compute the Latest item using the function
AddLatestColumn = Table.AddColumn(#"Changed Type", "Latest", each GetLatest([Item], #"Changed Type"), type text)
in
AddLatestColumn