Data Match with existing axes

Luke777

Board Regular
Joined
Aug 10, 2020
Messages
244
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I asked a similar question a week or two ago, but I was a little vague with exactly what I was looking for so the answers given (whilst great) often came with more questions from myself.

To skip to the important part I have a data source that looks like the following. All sheets are contained within one workbook. The below is taken from Worksheets("Source").

28606:30:0046
21406:30:0046
153506:30:0046
158006:30:0046
130706:30:0046
102906:30:0053
5706:30:0023
28606:45:0012
21406:45:0012
153506:45:0012
158006:45:0012
130706:45:0012
93207:30:0046
53807:30:0046
93207:45:0012
54207:45:0046
53807:45:0012
54208:00:0012
24108:00:0046
98908:00:0023


This is only the first 20 rows. The data currently goes down to 342, but is variable - though I would be quite shocked if the value was ever above 5k. The data is also sorted by date/time as per B:B - the earliest date/time will always be first.

I wish to create a table (I don't specifically mean the table feature in excel but table rather just organise the data in a more readable way) where the numbers in A:A act as a header across the top starting in C1. These headers should be unique (note values in A:A appear more than once, but the data should be consolidated if that makes sense). This 'table' will be on Worksheets("Results")

The date/time axis should begin in A4 - though this is where things are a little tricky. As per the source data, the first time would be 6:30 on the given date. Times are also dealt with in 15 minute intervals. however, notice that B12:B13 skips 45 minutes (three intervals or so). This means that using B:B as the Axis on the final table is not desireable as the axis may have missing chunks of time depending on the source data. To get around this, the date/time axis already exists on the result sheet - I have a bit of code that looks for the time in B1, places it in A4 and loops through rowno 4 To 148 (final row ~ 36 hours from start time but this doesn't really matter at this stage) adding 15 minutes each step.

With the example source data, the Results sheet should look like below - I'm looking for a VBA solution to this

ID#286214153515801307102957932538542241989
Part (ignore)/////////
Time
06:30:0046464646465323
06:45:001212121212
07:00:00
07:15:00
07:30:00464646
07:45:001212
08:00:00124623


The gap in B and rows 2,3 is deliberate, I'll be adding other data as part of a sep process in those spaces - though if needs be, these can be ignored and I can simply add an extra column and two new rows at a later time.

I think I've covered everything, but if I've missed anything crucial, please let me know.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Is this what you're looking for?

adressen mrexcel (version 1).xlsb
ABCDEFGHIJKLMN
1ID#286214153515801307102957932538542241989
2Part (ignore)
3Time
46:30:0046464646465323
56:45:001212121212
67:00:00
77:15:00
87:30:004646
97:45:00121246
108:00:00124623
Sheet3
Cell Formulas
RangeFormula
C1:N1C1=TRANSPOSE(FILTER(UNIQUE(Sheet1!A:A),UNIQUE(Sheet1!A:A)<>0))
C4:N10C4=XLOOKUP(C1#&ROUND(A4:A10,5),Sheet1!A1:A20&ROUND(Sheet1!B1:B20,5),Sheet1!C1:C20,"")
A5:A10A5=A4+TIME(0,15,0)
Dynamic array formulas.
 
Upvote 0
Is this what you're looking for?

adressen mrexcel (version 1).xlsb
ABCDEFGHIJKLMN
1ID#286214153515801307102957932538542241989
2Part (ignore)
3Time
46:30:0046464646465323
56:45:001212121212
67:00:00
77:15:00
87:30:004646
97:45:00121246
108:00:00124623
Sheet3
Cell Formulas
RangeFormula
C1:N1C1=TRANSPOSE(FILTER(UNIQUE(Sheet1!A:A),UNIQUE(Sheet1!A:A)<>0))
C4:N10C4=XLOOKUP(C1#&ROUND(A4:A10,5),Sheet1!A1:A20&ROUND(Sheet1!B1:B20,5),Sheet1!C1:C20,"")
A5:A10A5=A4+TIME(0,15,0)
Dynamic array formulas.
This is a potential solution - though I do not know how many IDs from A in the data source will exist & therefore can't say what the range is for the dynamic array forumula would be if that makes sense?

I'm also looking for a VBA solution, though this solution certainly seems viable if the above can be circumvented. Do you know if performing additional operations on the results of the formula will foul anything up? For example, I4 and N10 = 23. If I then run a bit of code that changes any "23" on the table to "chicken", will the dynamic array formulas be broken/vanish? I'm not overly familiar with DAFs, so sorry if this seems like a silly question

Thanks for the answer!
 
Upvote 0
Is this what you're looking for?

adressen mrexcel (version 1).xlsb
ABCDEFGHIJKLMN
1ID#286214153515801307102957932538542241989
2Part (ignore)
3Time
46:30:0046464646465323
56:45:001212121212
67:00:00
77:15:00
87:30:004646
97:45:00121246
108:00:00124623
Sheet3
Cell Formulas
RangeFormula
C1:N1C1=TRANSPOSE(FILTER(UNIQUE(Sheet1!A:A),UNIQUE(Sheet1!A:A)<>0))
C4:N10C4=XLOOKUP(C1#&ROUND(A4:A10,5),Sheet1!A1:A20&ROUND(Sheet1!B1:B20,5),Sheet1!C1:C20,"")
A5:A10A5=A4+TIME(0,15,0)
Dynamic array formulas.
I've had a go at implementing the formula - seems to do pretty much exactly what I want. The only issue is the formula takes quite a while to run on the full data set - I'll see if I can get the same result with a little extra speed by converting to VBA if that sounds like a good idea?
 
Upvote 0
If I then run a bit of code that changes any "23" on the table to "chicken", will the dynamic array formulas be broken/vanish?
This is set up in a dynamic formula that has a spill range. Unlike a regular formula that you would place and one cell and then drag to the other cells, with a spill range, there is only one formula in the whole spill area. The bad thing about them is you cannot have any data that would block that spill range, nor can you modify any individual cell. You could copy/paste values and then modify but you would lose the dynamic capability of the formula.
The only issue is the formula takes quite a while to run on the full data set
How large is your dataset? This is the good thing about a spill range. It calculates incredibly fast and should easily outperform VBA. I have datasets in the tens of thousands and nearing a hundred thousand rows that calculate almost instantly. If this is for some reason too slow, I would look more at power query instead of VBA. VBA is great for automation but not always the best option for performance. My opinion.
 
Upvote 0
This is set up in a dynamic formula that has a spill range. Unlike a regular formula that you would place and one cell and then drag to the other cells, with a spill range, there is only one formula in the whole spill area. The bad thing about them is you cannot have any data that would block that spill range, nor can you modify any individual cell. You could copy/paste values and then modify but you would lose the dynamic capability of the formula.
Oh man, that's a real shame - but that work around does work... inject the dynamic formula using vba, calculate, copy the results, clear the range, paste the results back in, then perform whatever actions i want/need on indivdual cells. Bit clunky I suppose but if I can't figure out a solid VBA solution, it'll do.

How large is your dataset? This is the good thing about a spill range. It calculates incredibly fast and should easily outperform VBA. I have datasets in the tens of thousands and nearing a hundred thousand rows that calculate almost instantly. If this is for some reason too slow, I would look more at power query instead of VBA. VBA is great for automation but not always the best option for performance. My opinion.
Data set is currently A1:C342 - not huge by any stretch of the imagination. I'd honestly be surprised if it ever broke the 1000 rows mark. The area the formula is running on is C4:AV148, which I suppose means there's quite a few cells that this formula needs to run on. I have a decent spec PC that I'm running this on and it just took two minutes and 42 seconds to recalculate this formula. I'm not sure if that's considered fast or not because I don't really know how long this would take on any other data sets/similar calculations.

I'm very unfamiliar with Power Query.. I had a stab at it the other day and got some very weird results. More research required lol. Is it possible to automate PQ using VBA?
 
Upvote 0
I have a decent spec PC that I'm running this on and it just took two minutes and 42 seconds to recalculate this formula. I'm not sure if that's considered fast or not because I don't really know how long this would take on any other data sets/similar calculations.
Definitely, not considered fast. In comparison, I had a workbook that took about 5 minutes to calculate but after the update of dynamic formulas and condensing pages by adding dropdown selections, it now literally calculates in under a second.

So, with your dataset at under a 1000 rows and columns out to AV, this should take no more than second to calculate and the most.

Of course, VBA may be a better solution just because of your need to edit cells afterwards. Good luck.
 
Upvote 0
So, with your dataset at under a 1000 rows and columns out to AV, this should take no more than second to calculate and the most.
Wonder why it is running so slowly for me? I'm running an AMD 5600X CPU if that means anything to you, though my GPU is significantly older...
 
Upvote 0
Wonder why it is running so slowly for me? I'm running an AMD 5600X CPU if that means anything to you, though my GPU is significantly older...
Answered my own question here - in the formula I've been referencing the whole column instead of the actual used range. Correcting this sped the process up to being near instant - Now I just need a way of making the 1:342 part dynamic within the formula so it automatically finds the used data range
 
Upvote 0
Here you go. Even more dynamic. :) This will find the end of your data on sheet1.

Book1
ABCDEFGHIJKLMN
1ID#286214153515801307102957932538542241989
2Part (ignore)
3Time
46:30 AM46464646465323
56:45 AM1212121212
67:00 AM
77:15 AM
87:30 AM4646
97:45 AM121246
108:00 AM124623
Sheet2
Cell Formulas
RangeFormula
C1:N1C1=TRANSPOSE(FILTER(UNIQUE(INDIRECT("Sheet1!A1:A" & MAX((Sheet1!A:A<>"")*(ROW(Sheet1!A:A))))),UNIQUE(INDIRECT("Sheet1!A1:A" & MAX((Sheet1!A:A<>"")*(ROW(Sheet1!A:A)))))<>0))
C4:N10C4=XLOOKUP(C1#&ROUND(A4:A10,5),Sheet1!A1:A20&ROUND(Sheet1!B1:B20,5),Sheet1!C1:C20,"")
A5:A10A5=A4+TIME(0,15,0)
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,478
Members
448,967
Latest member
visheshkotha

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