Faster Alternative to Array Formula

cbrown6305

New Member
Joined
Nov 12, 2018
Messages
13
Office Version
  1. 2016
Platform
  1. Windows
I have two tables, a table of charges and table of payments. I wrote the following array formula to bring a date of service from the charges table to the payments table using a common UniqueID filed that is common in the payments and charges table. The formula is in the payments table and brings in the date of service that is closest (but not later than) the related date of payment (related, as it, they have the same UniqueID). The formula is listed below

Excel Formula:
{=MAX(IF((ChargesbyID[Unique ID]=[@[Unique ID]])*(ChargesbyID[date_of_service]<=[@[date_of_payment]]),ChargesbyID[date_of_service]))}

ChargesbyID is the charges table. All "@[" items reference columns within the payments table.

The formula works, but the charges table table has about 300,000 rows and the payments table as 360,000 rows, so it takes a crazy amount of time to run (i.e., >30 min). Is there a different way of doing this that doesn't lock me out of excel for an hour?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
One thing that might help is to know what version of Excel you are using as that determines what is available to you. I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using. (Don’t forget to scroll down & ‘Save’)

1606714809604.png
 
Upvote 0
Uploads are below. I've updated my info - running office 2016.

Charges Table

Array Example 1.xlsx
BCD
5Unique IDdate_of_serviceSum of amount
6Location 1 | 10001/23/2018249
7Location 1 | 10005/30/2018132
8Location 1 | 100010/4/2018132
9Location 1 | 10002/5/2019249
10Location 1 | 10002/8/2019188
11Location 1 | 10006/6/2019180
12Location 1 | 100010/8/2019104
13Location 1 | 100012/11/20191,836
14Location 1 | 10002/12/2020132
Sheet1



Payments Table

Array Example 1.xlsx
FGHI
5Unique IDdate_of_paymentSum of paymentDate of Payment
6Location 1 | 10002/20/2018(249)1/23/2018
7Location 1 | 10006/12/2018(132)5/30/2018
8Location 1 | 10002/19/2019(156)2/8/2019
9Location 1 | 10003/1/2019(70)2/8/2019
10Location 1 | 10006/24/2019(108)6/6/2019
11Location 1 | 100010/22/2019(80)10/8/2019
12Location 1 | 100012/23/2019(569)12/11/2019
13Location 1 | 10002/21/2020(80)2/12/2020
14Location 1 | 10011/3/2018(46)1/0/1900
15Location 1 | 10012/5/2018(48)1/26/2018
Sheet1
Cell Formulas
RangeFormula
I6:I15I6=MAX(IF((ChargesbyID[Unique ID]=[@[Unique ID]])*(ChargesbyID[date_of_service]<=[@[date_of_payment]]),ChargesbyID[date_of_service]))
Press CTRL+SHIFT+ENTER to enter array formulas.


Formula in Date of Payment column of payments table:
Excel Formula:
{=MAX(IF((ChargesbyID[Unique ID]=[@[Unique ID]])*(ChargesbyID[date_of_service]<=[@[date_of_payment]]),ChargesbyID[date_of_service]))}
 
Upvote 0
I guess the best way to do this is using VBA. Each time any change to sheet, a calculation takes place. Furthermore, with that long formula in each cell, it will consume too much memory and makes you worksheet BIG.

I'm using 2016 but I'd say that 2013 can run the same code half the time the 2016 can ?
 
Upvote 0
Some clarifications are required.
In charged table only one Unique ID is shown. Does same Id repeats in many rows. Same Id is distributed to many rows or they are together in a set of rows (From Row 10 to Row25.
Secondly the ID's are sorted or not.
 
Upvote 0
There are many different Unique ID's in the charges table. Those IDs are unique to a location-account and each location-account has many different charges (in the ChargesbyID table) and many different payments (in the PaymentsID table). The UniqueID's are sorted alphabetically so UniqueIDs that are the same will come right after one another. The sorting for the ChargesID table is currently set a level 1: ChargesID alphabetically, level 2: date of service ascending.
 
Upvote 0
It is difficult to explain without File. I have tried.
In I6 of payments
VBA Code:
=MAX(((INDEX(ChargesbyID[Unique ID],$J6):INDEX(ChargesbyID[Unique ID],$K6)=[@[Unique ID]])*(INDEX(ChargesbyID[date_of_service],$J6):INDEX(ChargesbyID[date_of_service],$K6)<=[@[date_of_payment]]))*(INDEX(ChargesbyID[date_of_service],$J6):INDEX(ChargesbyID[date_of_service],$K6)))

In J6 of payments
VBA Code:
=IF($F6=$F5,J5,MATCH($F6,ChargesbyID[Unique ID],0))

In K6 of payments
VBA Code:
=IF($F6=$F5,K5,MATCH($F6,ChargesbyID[Unique ID],1))

Pull down all

J & K are helper columns in Payments table (assumed not used), can be hidden also.
J6 gives start position of F6 in charges table
K6 gives end position of F6 in charges table
I6 formula selects the Range from charges table from J6 K6 instead of entire range of table.
There by Search time is reduced drastically.
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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