Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

How to combine two rows based on condition?

I need assistance in combining two rows from a table based on a condition. Here is a sample table of my current data:

IDManager ID
A123A456
A123A678
B456A678
C789A678
B123A789

 

If an ID has two manager IDs, "A456" and "A678", then I want to only keep the row with "A456." Otherwise keep the record as normal. This is what I want to table to look like:

IDManager ID
A123A456
B456A678
C789A678
B123A789

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Anonymous  - You could do something like this in PowerQuery:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjQ0MlbSUXI0MTVTitVB8M3MLcB8J5AEEt/Z3MISRR6qHiQcGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, #"Manager ID" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Manager ID", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"MIN Manager ID", each List.Min([Manager ID]), type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Grouped Rows",{{"MIN Manager ID", "Manager ID"}})
in
    #"Renamed Columns"
I hope this helps. If it does, please Mark as a solution.
I also appreciate Kudos.
Nathan Peterson

 

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

@Anonymous - Is there something special about A456? What is the criteria that causes that one to be selected?

 

fhill
Resident Rockstar
Resident Rockstar

Are you trying to hard code each ID / Manager combination, or is there some Logic or Pattern to use in the selection?




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




Anonymous
Not applicable

@fhill

@natelpeterson

I think the answer is I want to hardcode. There are only two manager IDs that this applies to. Basically, if an ID does not belong to these two specific manager IDs, then their ID will not be duplicated in the table.

 

So I want a table that results from this logic: if an ID has manager ID "A456" AND "A678" THEN keep "A456" OTHERWISE, no change.

 

See the other reply if you want something more technical.  Here's a simple measure if you are trying to just make something small and easy.

 

New Measure on the Table:

Single_Mgr_Measure = IF(
                      COUNTA(Table3[ID]) = 1,  -- If there's only 1 Mgr Id..
                      MIN(Table3[Mgr ID]),        -- Return just that 1 Mgr ID
                                IF(
                                 CONTAINS(Table3,Table3[Mgr ID],   -- Else, If MGR ID CONTAINS 
                                      "A456"),"A456","Other Mgr"))      -- "A456" Return "A456", else "Other Mgr".
 
You can clean up the code as much as you need, and even inbed further IF Statements if you need to check for further combinations of mgrs.  Here's my final result.  I added BOB twice to the table with QQQ & RRR as Mgr IDs.
 
IDSingle_Mgr_Measure
A123A456
B123A789
B456A678
BobOther Mgr
C789A678



Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




Anonymous
Not applicable

@Anonymous  - You could do something like this in PowerQuery:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjQ0MlbSUXI0MTVTitVB8M3MLcB8J5AEEt/Z3MISRR6qHiQcGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, #"Manager ID" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Manager ID", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"MIN Manager ID", each List.Min([Manager ID]), type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Grouped Rows",{{"MIN Manager ID", "Manager ID"}})
in
    #"Renamed Columns"
I hope this helps. If it does, please Mark as a solution.
I also appreciate Kudos.
Nathan Peterson

 

Anonymous
Not applicable

I think the answer is I want to hardcode. There are only two manager IDs that this applies to. Basically, if an ID does not belong to these two specific manager IDs, then their ID will not be duplicated in the table.

 

So I want a table that results from this logic: if an ID has manager ID "A456" AND "A678" THEN keep "A456" OTHERWISE, no change.

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors