Hi @Iwona,
So maybe you should consider another table shape all together. Explore something like this. It will repeat the DUI fields across rows and create a single row for each BUI
let
DUIcols = List.Transform( { 1..List.Max( List.Transform( GroupCheck[DUI], each Text.Length( Text.Select( _, "," )) ) )+1 }, each "Column" & Text.From( _ ) ),
LastVal = Number.From( Text.Select( List.LastN( DUIcols, 1 ){0}, {"0".."9"})),
BUIcols = List.Transform( { LastVal+1..LastVal+1 + List.Max( List.Transform( ExpandBUI[BUI], each Text.Length( Text.Select( _, "," )))) }, each "Column" & Text.From( _ ) ),
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rZJNa8MwDIb/S85ClSzbca5bYR2UDNptMEKPPfew/w+TnC877Q6DBUfYiV/r1SMPQ7MHISDWwLTjdufIEQTo3+CpJ7af+49xqk9/s/F1/a7e/tZcYGiOwPAOp5OIB4roxWIQ/QLskHmexLz7EzQjBBTJy9GG41DaYN/+yYi+lRPS48yJy05cNsDIHbweD+ezzQNPAjcJEhAhaWpBb45fTrovze5T7b5D75eliIAeSMUH5YCOqvrcv9ZHmTEli2pdLVJn4Mf6ciWb+ljzGwqL7cxBkOIDjUxJVOPRnGtcNHHNw60yLbAkDLHCok0PWyxhxSJeuMTyfODfsYwXrhwVki5xbrYiaQ2MIWlR3NTKeyRZkFtOyYqc9nVr+++RrBq9Qm65JqJ1P9D4rcajzPsUHcV8tZQhFwx1KRVDyQdefgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
FilterRows = Table.SelectRows(Source, each not Text.StartsWith([Column1], "V")),
AddIndex = Table.AddIndexColumn(FilterRows, "Index", 1, 1, Int64.Type),
AddCheck = Table.AddColumn(AddIndex, "Check", each if Text.StartsWith([Column1],"D") then [Index] else null),
FillDownCheck = Table.FillDown(AddCheck,{"Check"}),
GroupCheck = Table.Group(FillDownCheck, {"Check"}, {{"DUI", each Text.Combine( {[Column1]{0}}, ",") , type nullable text}, {"BUI", each List.Skip( [Column1], 1 ) }})[[DUI], [BUI]],
SplitDuiCol = Table.SplitColumn(GroupCheck, "DUI", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), DUIcols),
ExpandBUI = Table.ExpandListColumn(SplitDuiCol, "BUI"),
SplitBuiCol = Table.SplitColumn(ExpandBUI, "BUI", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), BUIcols )
in
SplitBuiCol
Sample file
eDNA - Iwona Table with 2 keys.pbix (12.7 KB)
I hope this is helpful