Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
The task I need to accomplish is as follows:
I have two data sets. One is EVENTS and one is WEATHER.
Each entry in the EVENTS table has a Date/Time stamp when that the event occured.
Each WEATHER entry has an hourly observation (with a Date/Time stamp of when the observation was taken....there may be more than one observation per hour)
What I want to do is basically MERGE/JOIN/RELATE these two tables based on the DATE/TIME stamps of the EVENT and the WEATHER Observation. Now, they obviously won't normally happen at the exact same time, so what I would like to do is relate the EVENT to the CLOSEST WEATHER Observation Date/Time.
Any ideas on how I can manage this?
Sorry for being a bit late... The solution is attached.
Please remember that this code works correctly on condition that for each Event there is at least 1 weather observation in the Weather table on the same day as the Event.
Best
D
Ya, this is exactly what I want to do, and figured PQ was the way to do it, I'm just not sure how to do the calculation you are refering to.
To clear up some ambiquity, I am looking to relate to the "closest" time...and by that, I mean, the most recent wx observation, either earlier or later than the event in question.
So, say I have an event that occured at 19-May-2020 @ 17:37
And I have 3 Wx Observations for the 19th of May at 17:00, 17:30, 18:00.
My goal is to be able to relate the event at 17:37 with the Wx Observation at 17:30, as it is the "closest" to the time of the event.
Yes, can 10000% guarantee that. It's an aviation weather service. In theory there should be at least one per hour, but it's not unheard of for the odd one to get missed, doesn't happen often though. As for once a day? Yes. I'd think it would take some fairly catastrophic event to not get at least that.
@elietech what defines closest? Share example data and expected output and that will help to provide the solution. Your problem is surely clear but what defines closest, needs a bit more understanding of this.
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 41 | |
| 38 | |
| 36 | |
| 30 | |
| 28 |
| User | Count |
|---|---|
| 128 | |
| 88 | |
| 79 | |
| 67 | |
| 62 |