Forum Discussion
mmiklauz1
1 year agoRegular Visitor
Extra rows vs second table
Hi everyone, I'm struggling a few days whit this problem so I would appreciate your help. I need create a dynamic measure to show only the "extra rows" i each table: so for example I have two source...
- 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.
techies
1 year agoSuper User
Hi mmiklauz1 please try this
create a table like this
Amounts =
UNION (
DISTINCT ( SELECTCOLUMNS ( Table1, "Amount", Table1[Amount] ) ),
DISTINCT ( SELECTCOLUMNS ( Table2, "Amount", Table2[Amount] ) )
)
then the measures---
Table1 Count =
CALCULATE (
COUNTROWS ( Table1 ),
TREATAS ( VALUES ( Amounts[Amount] ), Table1[Amount] )
)
Extra in Table1 =
VAR Count1 = [Table1 Count]
VAR Count2 = [Table2 Count]
RETURN
IF (Count1 > Count2, Count1 - Count2)
Table2 Count =
CALCULATE (
COUNTROWS ( Table2 ),
TREATAS ( VALUES ( Amounts[Amount] ), Table2[Amount] )
)
Extra in Table2 =
VAR Count1 = [Table1 Count]
VAR Count2 = [Table2 Count]
RETURN
IF (Count2 > Count1, Count2 - Count1)