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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
joelv67
Frequent Visitor

List.First(List.Select()) comparing column table to containing table

background:

I have in my main table a CreateDate. I have created a column of data from the main table, for each row, it contains 1 or more records. I am trying to grab the First Date from the newtable where the CreateDate is < the current Records CreateDate.

 

Previosly, I was grabbing First record like so:

= Table.AddColumn(#"Merged Queries1", "StartDate", each List.First([NewTable][CreateDate]))

 

This grabs the CreateDate correctly, but just grabbign the 1st regardless.

 

I would like to change this to something like this:
= Table.AddColumn(#"Added Custom3", "StartDate2", each List.First( List.Select([NewTable][CreateDate], _ < [CreateDate] )))

 

I get the following error:
Expression.Error: We cannot apply operator > to types Record and DateTime.
Details:
    Operator=>
    Left=Record
    Right=1/12/2017 12:02:31 AM

 

Any ideas on how I can do this?

Sample Data:
CreateDate | Application | Severity | NewTable

1/12/2017 12:02:31 | TestApp | Info | <table>

 

<table> contents:
1/12/2017 12:01:00 | TestApp | Info

1/13/2017 12:01:00 | TestApp | Info

 

Thank you for any help

 

Joel

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

sorry, there was an Earlier missing:

 

= Table.AddColumn(#"Added Custom3", "StartDate2", (Earlier) => List.First( List.Select(Earlier[NewTable][CreateDate], each _ < Earlier[CreateDate] )))

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

4 REPLIES 4
ImkeF
Community Champion
Community Champion

Pls try:

 

= Table.AddColumn(#"Added Custom3", "StartDate2", (Earlier) => List.First( List.Select([NewTable][CreateDate], each _ < Earlier[CreateDate] )))

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

joelv67
Frequent Visitor

Thank you for the quick response. I am now getting this error:

Expression.Error: There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?

ImkeF
Community Champion
Community Champion

sorry, there was an Earlier missing:

 

= Table.AddColumn(#"Added Custom3", "StartDate2", (Earlier) => List.First( List.Select(Earlier[NewTable][CreateDate], each _ < Earlier[CreateDate] )))

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

joelv67
Frequent Visitor

Thank you so much!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.