Forum Discussion
Extra rows vs second table
- 1 year ago
Hi mmiklauz1,
Thank you for reaching out to the Microsoft Fabric Forum Community. I’ve gone ahead and reproduced your scenario using Power Query.
Below is the M code I used in Power BI to reproduce your scenario:let Table1 = #table({"Value"}, {{5},{5},{5},{5},{4},{3},{2},{1}}), Table2 = #table({"Value"}, {{5},{3},{2},{1}}), Table1Grouped = Table.Group(Table1, {"Value"}, {{"Count1", each Table.RowCount(_), Int64.Type}}), Table2Grouped = Table.Group(Table2, {"Value"}, {{"Count2", each Table.RowCount(_), Int64.Type}}), Merged = Table.NestedJoin(Table1Grouped, {"Value"}, Table2Grouped, {"Value"}, "T2", JoinKind.LeftOuter), Expanded = Table.ExpandTableColumn(Merged, "T2", {"Count2"}), WithReplacedNulls = Table.ReplaceValue(Expanded, null, 0, Replacer.ReplaceValue, {"Count2"}), WithExtra = Table.AddColumn(WithReplacedNulls, "Extra", each List.Max({[Count1] - [Count2], 0}), Int64.Type), Filtered = Table.SelectRows(WithExtra, each [Extra] > 0), WithRepeated = Table.AddColumn(Filtered, "Repeated", each List.Repeat({[Value]}, [Extra])), ExpandedRows = Table.ExpandListColumn(WithRepeated, "Repeated"), FinalOutput = Table.SelectColumns(ExpandedRows, {"Repeated"}), Renamed = Table.RenameColumns(FinalOutput, {{"Repeated", "Value"}}) in RenamedI’m also attaching the output screenshot and .pbix file here for your reference so you can explore it end-to-end:
If this information is helpful, please “Accept it as a solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.
Hi mmiklauz1,
Thank you for reaching out to the Microsoft Fabric Forum Community. I’ve gone ahead and reproduced your scenario using Power Query.
Below is the M code I used in Power BI to reproduce your scenario:
let
Table1 = #table({"Value"}, {{5},{5},{5},{5},{4},{3},{2},{1}}),
Table2 = #table({"Value"}, {{5},{3},{2},{1}}),
Table1Grouped = Table.Group(Table1, {"Value"}, {{"Count1", each Table.RowCount(_), Int64.Type}}),
Table2Grouped = Table.Group(Table2, {"Value"}, {{"Count2", each Table.RowCount(_), Int64.Type}}),
Merged = Table.NestedJoin(Table1Grouped, {"Value"}, Table2Grouped, {"Value"}, "T2", JoinKind.LeftOuter),
Expanded = Table.ExpandTableColumn(Merged, "T2", {"Count2"}),
WithReplacedNulls = Table.ReplaceValue(Expanded, null, 0, Replacer.ReplaceValue, {"Count2"}),
WithExtra = Table.AddColumn(WithReplacedNulls, "Extra", each List.Max({[Count1] - [Count2], 0}), Int64.Type),
Filtered = Table.SelectRows(WithExtra, each [Extra] > 0),
WithRepeated = Table.AddColumn(Filtered, "Repeated", each List.Repeat({[Value]}, [Extra])),
ExpandedRows = Table.ExpandListColumn(WithRepeated, "Repeated"),
FinalOutput = Table.SelectColumns(ExpandedRows, {"Repeated"}),
Renamed = Table.RenameColumns(FinalOutput, {{"Repeated", "Value"}})
in
Renamed
I’m also attaching the output screenshot and .pbix file here for your reference so you can explore it end-to-end:
If this information is helpful, please “Accept it as a solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.
Hi mmiklauz1,
I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please accept it as a solution and give it a 'Kudos' so other community members with similar problems can find a solution faster.
Thank you.