PowerQuery - Filter to only earliest record

DaveBlakeMAAT

Board Regular
Joined
Feb 28, 2016
Messages
190
Hi

I have a small PowerQuery issue which I am hoping one of you fine ladies or gents can help with

My data is broadly as follows:-

ID JobNo DateOnSite TimeOnSite
1 1234 01/01/2017 00:53
2 1234 02/01/2017 09:47
3 4567 02/02/2018 08:56
4 4567 03/02/2018 10:56

I need to be able to filter the records so that I show the earliest date (initial onsite time) for each job number (lowest ID number for each job number will always be the initial onsite date).

To give some context, I need to calculate initial response time/date for compliance reporting and therefore only interested in the initial visit and this query will then be merged into another larger query which I know how to do, it is just this initial filtering that I am stuck on, so any pointers in the right direction will be greatly appreciated.

Many thanks

Dave
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi Dave,
I'll try to help you or maybe give you an appropriate hint. Since English is not my native language, it may be that I did not understand you correctly ...


In order to filter only the youngest entry from each JobNo and output it in a new query, I do this in Power Query:
* Load data into the editor
* TimeOnSite may be set as a type of time
* Custom DateTime column using this formula: Number.From ([DateOnSite]) + Number.From ([TimeOnSite])
* Sort JobNo in ascending order
* Sort DateTime in ascending order
* JobNo -> remove duplicates
* Delete column DateTime


Since my M code contains many German names, I leave it in this description.

Best regards
Guenther
 
Upvote 0
Thanks Guenther

That is almost perfect for what I need, I have a small issue in the fact that job numbers are negative if not confirmed but I can get around that using a RIGHT function and sorting from that. I think as normal I was overthinking the problem!

Your help has been very much appreciated.

Regards

Dave
 
Upvote 0
Hi Dave,
thanks for the feedback.
You can also try using the Number.Abs function in a new help column for sorting. Number.Abs([ProductNumber]) will always return a positive value.

Regards
Guenther
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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