Forum Discussion
Gozde
Helper I
8 years agoAdd rows to table according to grouping in different table
Hi, I would like to add rows to one table ( or combine two tables) according to group number from another table. These are what I have: Table 1 Name Part A x1 B y1 B x1 ...
- 8 years ago
Zubair_Muhammad
Community Champion
8 years ago
Try with this code
New Table =
VAR Mytable1 =
ADDCOLUMNS (
Table1,
"My Group", CALCULATE ( FIRSTNONBLANK ( Table2[Group], 1 ) )
)
VAR JoinTables =
ADDCOLUMNS (
GENERATEALL (
SELECTCOLUMNS (
mytable1,
"Name", [Name],
"My Group", [My Group],
"My Part", [Part]
),
FILTER ( Table2, Table2[Group] = [My Group] )
),
"Final Part", IF ( ISBLANK ( [Part] ), [My Part], [Part] )
)
RETURN
SELECTCOLUMNS (
JoinTables,
"Name", [Name],
"Group", [Group],
"Part", [Final Part]
)Zubair_Muhammad
Community Champion
8 years ago- Gozde8 years ago
Helper I
Yes, changing generate to generateall solve the issue!
Thank you very much,
Gozde
- Zubair_Muhammad8 years ago
Community Champion
Actually in addition to GenerateAll there was a subtle issue with Parts Column as well :smileytongue:
- Gozde8 years ago
Helper I
Nope, When I add your last code, again parts without group number are disappering at final table.
I tried your code with the example:
This is the output.
Name Part Group A x1 2 A x2 2 B x1 2 B x2 2 C x1 1 C x2 1 - Zubair_Muhammad8 years ago
Community Champion
- Gozde8 years ago
Helper I
Thanks a lot!
I found my syntax error :)