Hi @Mahendran_C_S. Here's a full example using the sample data you provided. There are three separate queries (Numbers, toBinaryPositions, and Countries). For each query, you can create a Blank Query in the PQ Editor, name it as shown in the comment, and then paste the code for that query into the Advanced Editor.
// Numbers
let
Source = #table(type table [Number=number], {{39}, {78}}),
#"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "BinaryPositions", each toBinaryPositions([Number]), type list),
#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "BinaryPositions"),
#"Merged Queries" = Table.NestedJoin(#"Expanded Custom", {"BinaryPositions"}, Countries, {"Number"}, "Countries", JoinKind.LeftOuter),
#"Expanded Countries" = Table.ExpandTableColumn(#"Merged Queries", "Countries", {"Country Name"}, {"Country Name"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Countries",{"BinaryPositions"}),
#"Grouped Rows" = Table.Group(#"Removed Columns", {"Index"}, {{"Number", each List.Max([Number]), type number}, {"Rows", each _, type table [Number=number, Index=number, Country Name=nullable text]}}),
#"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Country Names", each Text.Combine([Rows][Country Name], ",")),
#"Removed Columns1" = Table.RemoveColumns(#"Added Custom1",{"Index", "Rows"})
in
#"Removed Columns1"
// toBinaryPositions
let
Source = (val) =>
let
div = List.Generate(() => val, (x) => x >= 1, (x) => Number.RoundDown(x / 2)),
mod = List.Transform(div, each Number.Mod(_, 2)),
pos = List.Select(List.Positions(mod), each mod{_} = 1)
in
List.Transform(pos, each _ + 1)
in
Source
// Countries
let
Source = #table(
type table [Number=number, Country Name=text],
{
{1, "India"},
{2, "Canada"},
{3, "France"},
{4, "USA"},
{5, "UAE"},
{6, "Singapore"},
{7, "Malaysia"}
}
)
in
Source