List.RemoveItems with condition

donkey shrek

New Member
Joined
Nov 15, 2022
Messages
26
Office Version
  1. 365
Platform
  1. Windows
I have a column that contains lists of dates. How do I remove dates from those lists where value does not = x?
1673335890544.png
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
The second argument to RemoveItems is a list of the items you want removed, so just supply any date/times you want removed there.
 
Upvote 0
Ah, I think I misunderstood. You probably want List.Select instead so you can specify the criteria for the ones you want to keep.
 
Upvote 0
The second argument to RemoveItems is a list of the items you want removed, so just supply any date/times you want removed there.
How do I specify it to remove dates where not = to specific date?
 
Upvote 0
Ah, I think I misunderstood. You probably want List.Select instead so you can specify the criteria for the ones you want to keep.
This is my current code. Time contains lists of DateTimes. I want to remove values in those lists that contain [Start Date] - a Date value

Power Query:
= Table.TransformColumns(#"Removed Columns1", Time, each List.Select([Time], each _ contains [Start Date]))
 
Upvote 0
I'm sure it is possible with TransformColumns (getting the reference to each row's [Start Date] field eludes me at the moment) but you could use something like this:

Power Query:
=Table.FromRecords(Table.TransformRows(#"Removed Columns1", (row) => Record.TransformFields(row, {"Time", each List.Select(_, (d) => DateTime.Date(d) <> row[Start Date])})))

Or add a column using something like
Power Query:
List.Select([Time], each DateTime.Date(_) <> [Start Date]))

and then remove the original.
 
Upvote 0
Solution
I'm sure it is possible with TransformColumns (getting the reference to each row's [Start Date] field eludes me at the moment) but you could use something like this:

Power Query:
=Table.FromRecords(Table.TransformRows(#"Removed Columns1", (row) => Record.TransformFields(row, {"Time", each List.Select(_, (d) => DateTime.Date(d) <> row[Start Date])})))

Or add a column using something like
Power Query:
List.Select([Time], each DateTime.Date(_) <> [Start Date]))

and then remove the original.
Thank you! Just changed it abit and it works, this is my final code:

Power Query:
= Table.AddColumn(Custom1, "Custom", each let SD = [Start Date] in List.Select([Time], each DateTime.Date(_) = SD))
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top