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! Request now

Reply
efilipe
Helper IV
Helper IV

Tables merge with conditional

Hi guys,

 

I need to merge two tables:

 

First table - Car

____________________________________________________________

| Car             |  TireSize       | Dimension         |    Speed    |

---------------------------------------------------------------

| Brand_1     |  16                 |  46                     |  4              |

| Brand_2     |  14                 |  45                     |  2              |

| Brand_3     |  16                 |  46                     |  5              |

---------------------------------------------------------------

Second Table - Tire

____________________________________________________________

| Tire            |  TireSize       | Dimension         |    Speed    |

---------------------------------------------------------------

| Tire_1        |  16                 |  46                     |  5              |

| Tire_2        |  14                 |  45                     |  2              |

---------------------------------------------------------------

I need to merge both columns, knowing:

Car.TireSize = Tire.TireSize

Car.Dimension = Tire.Dimension

Car.Speed <= Tire.Speed 

My problem is with the <=   🙂

Any help out there?

 

Thanks!



1 ACCEPTED SOLUTION
VasTg
Memorable Member
Memorable Member

@efilipe 

 

Its easy to do it in Transform data/ Query editor. 

 

1. Merge Car and Tire(Left outer - all rows from Car) based on (Tiresize and Dimension)

2. Expand the table column(Tire).

3. Create a new conditional column - If Speed column from Tire is >= speed column from Car then '1' else '0'.

4. select value 1 from the column created from step 3.

 

 

M query:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WUnAqSsxLiTc8tEABjJR0lIC0oRmMj4kgKkzwqEBRh1VWKVYHbrURmtXYdSAbaUqc1UYErTamla+xu1ApNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#" Car             " = _t, #"  TireSize       " = _t, #" Dimension         " = _t, #"    Speed    " = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{" Car             ", type text}, {"  TireSize       ", Int64.Type}, {" Dimension         ", Int64.Type}, {"    Speed    ", Int64.Type}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"  TireSize       ", " Dimension         "}, Tire, {"  TireSize       ", " Dimension         "}, "Tire", JoinKind.LeftOuter),
#"Expanded Tire" = Table.ExpandTableColumn(#"Merged Queries", "Tire", {" Tire            ", "  TireSize       ", " Dimension         ", "    Speed    "}, {"Tire. Tire            ", "Tire.  TireSize       ", "Tire. Dimension         ", "Tire.    Speed    "}),
#"Added Conditional Column" = Table.AddColumn(#"Expanded Tire", "Flag", each if [#"Tire.    Speed    "] >= [#"    Speed    "] then 1 else 0),
#"Filtered Rows" = Table.SelectRows(#"Added Conditional Column", each ([Flag] = 1))
in
#"Filtered Rows"

 

You could even edit the M query to remove the coditional column and the filtered rows as below.

 

#"Filtered Rows" = Table.SelectRows(#"Expanded Tire", each ([#"Tire.    Speed    "] >= [#"    Speed    "]))

 

If this helps, mark it as a solution.

Kudos are nice too.

 

 

 

Connect on LinkedIn

View solution in original post

3 REPLIES 3
VasTg
Memorable Member
Memorable Member

@efilipe 

 

Its easy to do it in Transform data/ Query editor. 

 

1. Merge Car and Tire(Left outer - all rows from Car) based on (Tiresize and Dimension)

2. Expand the table column(Tire).

3. Create a new conditional column - If Speed column from Tire is >= speed column from Car then '1' else '0'.

4. select value 1 from the column created from step 3.

 

 

M query:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WUnAqSsxLiTc8tEABjJR0lIC0oRmMj4kgKkzwqEBRh1VWKVYHbrURmtXYdSAbaUqc1UYErTamla+xu1ApNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#" Car             " = _t, #"  TireSize       " = _t, #" Dimension         " = _t, #"    Speed    " = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{" Car             ", type text}, {"  TireSize       ", Int64.Type}, {" Dimension         ", Int64.Type}, {"    Speed    ", Int64.Type}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"  TireSize       ", " Dimension         "}, Tire, {"  TireSize       ", " Dimension         "}, "Tire", JoinKind.LeftOuter),
#"Expanded Tire" = Table.ExpandTableColumn(#"Merged Queries", "Tire", {" Tire            ", "  TireSize       ", " Dimension         ", "    Speed    "}, {"Tire. Tire            ", "Tire.  TireSize       ", "Tire. Dimension         ", "Tire.    Speed    "}),
#"Added Conditional Column" = Table.AddColumn(#"Expanded Tire", "Flag", each if [#"Tire.    Speed    "] >= [#"    Speed    "] then 1 else 0),
#"Filtered Rows" = Table.SelectRows(#"Added Conditional Column", each ([Flag] = 1))
in
#"Filtered Rows"

 

You could even edit the M query to remove the coditional column and the filtered rows as below.

 

#"Filtered Rows" = Table.SelectRows(#"Expanded Tire", each ([#"Tire.    Speed    "] >= [#"    Speed    "]))

 

If this helps, mark it as a solution.

Kudos are nice too.

 

 

 

Connect on LinkedIn

This is actually a big tabled. There are a lot of Speeds. About 10 of them.

Makes sense! I'll try! Thanks!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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