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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
DieterH
New Member

RemoveMatchingRows

Hello,

I tried to remove matching rows. I used the example out of documentation

Table.RemoveMatchingRows(Table.FromRecords(

{ [OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100.0],

[OrderID = 2, CustomerID = 1, Item = "1 lb. worms", Price = 5.0],

[OrderID = 3, CustomerID = 2, Item = "Fishing net", Price = 25.0],

[OrderID = 4, CustomerID = 3, Item = "Fish tazer", Price = 200.0],

[OrderID = 5, CustomerID = 3, Item = "Bandaids", Price = 2.0],

[OrderID = 6, CustomerID = 1, Item = "Tackle box", Price = 20.0],

[OrderID = 7, CustomerID = 5, Item = "Bait", Price = 3.25],

[OrderID = 8, CustomerID = 5, Item = "Fishing Rod", Price = 100.0],

[OrderID = 9, CustomerID = 6, Item = "Bait", Price = 3.25] } ),

{[CustomerID = 3]}, "CustomerID")

I have 2 questions.

1. This code only works with the condition =. If I use [CustomerID <= 3] it brings up an error message. How can I make a condition like <= 3?

2. If I have a Date-Field instead of numeric like in the example above. It is not possible to use Date-functions, like [Date.Year(MyDate) = 2016]. Isn`t it possible to use Functions inside RemoveMatchedRows?

Thanks for your help

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @DieterH,

 

For your requirement, you can refer to below formula:

 

>>1. This code only works with the condition =. If I use [CustomerID <= 3] it brings up an error message. How can I make a condition like <= 3?

 

let
    Source = Table.RemoveMatchingRows(Table.FromRecords(

{ [OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100.0],

[OrderID = 2, CustomerID = 1, Item = "1 lb. worms", Price = 5.0],

[OrderID = 3, CustomerID = 2, Item = "Fishing net", Price = 25.0],

[OrderID = 4, CustomerID = 3, Item = "Fish tazer", Price = 200.0],

[OrderID = 5, CustomerID = 3, Item = "Bandaids", Price = 2.0],

[OrderID = 6, CustomerID = 1, Item = "Tackle box", Price = 20.0],

[OrderID = 7, CustomerID = 5, Item = "Bait", Price = 3.25],

[OrderID = 8, CustomerID = 5, Item = "Fishing Rod", Price = 100.0],

[OrderID = 9, CustomerID = 6, Item = "Bait", Price = 3.25] } ),

{[CustomerID = 3]}, each [CustomerID] <=3)

in
    Source

 

>>2. If I have a Date-Field instead of numeric like in the example above. It is not possible to use Date-functions, like [Date.Year(MyDate) = 2016]. Isn`t it possible to use Functions inside RemoveMatchedRows?

 

Yes, it is possible. If you want to keep use the remove mathch row funciton, you can modify the condition query to Date.Year([Date ColumnName]) <> 2016.

 

In addition, you can also use Table.SelectRows to achieve your requirement.

 

Table.SelectRows(Table.FromRecords(

{ [OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100.0],

[OrderID = 2, CustomerID = 1, Item = "1 lb. worms", Price = 5.0],

[OrderID = 3, CustomerID = 2, Item = "Fishing net", Price = 25.0],

[OrderID = 4, CustomerID = 3, Item = "Fish tazer", Price = 200.0],

[OrderID = 5, CustomerID = 3, Item = "Bandaids", Price = 2.0],

[OrderID = 6, CustomerID = 1, Item = "Tackle box", Price = 20.0],

[OrderID = 7, CustomerID = 5, Item = "Bait", Price = 3.25],

[OrderID = 8, CustomerID = 5, Item = "Fishing Rod", Price = 100.0],

[OrderID = 9, CustomerID = 6, Item = "Bait", Price = 3.25] } ),

{[CustomerID = 3]}, each [CustomerID] >3 and DateYear([Date]) = 2016 )

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @DieterH,

 

For your requirement, you can refer to below formula:

 

>>1. This code only works with the condition =. If I use [CustomerID <= 3] it brings up an error message. How can I make a condition like <= 3?

 

let
    Source = Table.RemoveMatchingRows(Table.FromRecords(

{ [OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100.0],

[OrderID = 2, CustomerID = 1, Item = "1 lb. worms", Price = 5.0],

[OrderID = 3, CustomerID = 2, Item = "Fishing net", Price = 25.0],

[OrderID = 4, CustomerID = 3, Item = "Fish tazer", Price = 200.0],

[OrderID = 5, CustomerID = 3, Item = "Bandaids", Price = 2.0],

[OrderID = 6, CustomerID = 1, Item = "Tackle box", Price = 20.0],

[OrderID = 7, CustomerID = 5, Item = "Bait", Price = 3.25],

[OrderID = 8, CustomerID = 5, Item = "Fishing Rod", Price = 100.0],

[OrderID = 9, CustomerID = 6, Item = "Bait", Price = 3.25] } ),

{[CustomerID = 3]}, each [CustomerID] <=3)

in
    Source

 

>>2. If I have a Date-Field instead of numeric like in the example above. It is not possible to use Date-functions, like [Date.Year(MyDate) = 2016]. Isn`t it possible to use Functions inside RemoveMatchedRows?

 

Yes, it is possible. If you want to keep use the remove mathch row funciton, you can modify the condition query to Date.Year([Date ColumnName]) <> 2016.

 

In addition, you can also use Table.SelectRows to achieve your requirement.

 

Table.SelectRows(Table.FromRecords(

{ [OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100.0],

[OrderID = 2, CustomerID = 1, Item = "1 lb. worms", Price = 5.0],

[OrderID = 3, CustomerID = 2, Item = "Fishing net", Price = 25.0],

[OrderID = 4, CustomerID = 3, Item = "Fish tazer", Price = 200.0],

[OrderID = 5, CustomerID = 3, Item = "Bandaids", Price = 2.0],

[OrderID = 6, CustomerID = 1, Item = "Tackle box", Price = 20.0],

[OrderID = 7, CustomerID = 5, Item = "Bait", Price = 3.25],

[OrderID = 8, CustomerID = 5, Item = "Fishing Rod", Price = 100.0],

[OrderID = 9, CustomerID = 6, Item = "Bait", Price = 3.25] } ),

{[CustomerID = 3]}, each [CustomerID] >3 and DateYear([Date]) = 2016 )

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thanks so much for your help, Xiaoxin, but there is something I don't understand about the syntax and semantics of this. The last two arguments to Table.RemoveMatchingRows are

{[CustomerID = 3]}, each [CustomerID] <=3

which seems to say to remove all rows where the CustomerID column is equal to 3, but then the matching criterion says CustomerID smaller than or equal to 3? How should I interpret this? They seem to specify two different sets of rows. I have read the documentation for Table.RemoveMatchingRows, but that didn't make me any wiser. Thanks for any pointers!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors