How to sort by latest date in SUMPRODUCT

lost_in_the_sauce

Board Regular
Joined
Jan 18, 2021
Messages
128
Office Version
  1. 365
Platform
  1. Windows
I have an array of sales data from multiple stores (180), and the data is entered by the stores at the end of each month. It all goes into an array. However, some stores will update their numbers, and in the array it adds a new line with a date/timestamp. For example, New York has 4 entries for February 2022, with different timestamps, and I only want the last one.

Currently I am using SUMPRODUCT like this:

=SUMPRODUCT((Data!$B$2:$B$1214=$B18)*(Data!$J$1:$P$1=C$2)*(Data!$F$2:$F$1214=$A18)*(Data!$J$2:$P$1214))

where $B18 is the month, C$2 is the $ category (sales, rent, etc), $A18 is the location, and $J:$2:$P$14 is the array of number values.

I have a column G with the timestamp. I've tried MAX but it looks like it pulls everything, I just want to add the condition for the latest date that also matches the other 3 conditions.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
For someone to recreate your scenario requires a lot of thought and figuring out?
Can you help the forum help you by using the xl2bb add in and giving snapshot of the pertinent cells. There is a link to it below.
You can anonymize as necessary. You have Cell $B18 as a match value, but B2:B1214 is also a lookup range, which is okay, but it is confusing without seeing your worksheet. What is in cell $A18 (It is one of your lookup values)?
 
Upvote 0
Is the the timestamp a complete date and time value? Is the month only a text expression? what is the max expression you are using, including the cell references (are there any non values in that range)?
 
Upvote 0
Also, i think this portion is a typo: $J:$2:$P$14 is it supposed to be $J$2:$P$1214?
 
Upvote 0
For someone to recreate your scenario requires a lot of thought and figuring out?
Can you help the forum help you by using the xl2bb add in and giving snapshot of the pertinent cells. There is a link to it below.
You can anonymize as necessary. You have Cell $B18 as a match value, but B2:B1214 is also a lookup range, which is okay, but it is confusing without seeing your worksheet. What is in cell $A18 (It is one of your lookup values)?
Waiting on IT to see if I'll be allowed to add the extension on my work laptop.

>Also, i think this portion is a typo: $J:$2:$P$14 is it supposed to be $J$2:$P$1214?

Yep, that was a typo on my part. You are correct.

The attached image is a small bit of the array, but in this example I want the cell to pull the 4th entry for Feb Revenue for New York, which would be the 8th row, currently it pulls 5-8.

The timestamp is in format: 5/16/2022 6:03:57 PM or mm/dd/yy h:mm AM/PM under custom. There are no non values in the column.
 

Attachments

  • mrexcel.JPG
    mrexcel.JPG
    159.6 KB · Views: 9
Upvote 0
Waiting on IT to see if I'll be allowed to add the extension on my work laptop.

>Also, i think this portion is a typo: $J:$2:$P$14 is it supposed to be $J$2:$P$1214?

Yep, that was a typo on my part. You are correct.

The attached image is a small bit of the array, but in this example I want the cell to pull the 4th entry for Feb Revenue for New York, which would be the 8th row, currently it pulls 5-8.

The timestamp is in format: 5/16/2022 6:03:57 PM or mm/dd/yy h:mm AM/PM under custom. There are no non values in the column.
i understand about IT issues!
 
Upvote 0
can you post the text of the formula that is giving you problems?
 
Upvote 0
How does this work:
Book1
ABCDEFGHIJ
1MonthYearNameCreated DateRevenue
2January2022New York2022-02-20 01:43341,716.77
3January2022New York2022-05-16 17:590.00
4January2022New York2022-05-16 18:03341,716.77
5February2022New York2022-03-10 14:21533,074.54
6February2022New York2022-03-12 17:11385,871.20
7February2022New York2022-05-16 18:000.00
8February2022New York2022-05-16 18:04385,871.20
9March2022New York2022-04-11 14:20494203.4
10Apri2022New York2022-05-17 17:17412691.43
11May2022New York2022-06-11 18:12275129.77
12
13
14February385871.2
Sheet1
Cell Formulas
RangeFormula
C14C14=SUM(((--(MAX((--(B14=$B$2:$B$11))*($G$2:$G$11))=$G$2:$G$11))*($J$2:$J$11)))
 
Upvote 1
Solution
How does this work:
Book1
ABCDEFGHIJ
1MonthYearNameCreated DateRevenue
2January2022New York2022-02-20 01:43341,716.77
3January2022New York2022-05-16 17:590.00
4January2022New York2022-05-16 18:03341,716.77
5February2022New York2022-03-10 14:21533,074.54
6February2022New York2022-03-12 17:11385,871.20
7February2022New York2022-05-16 18:000.00
8February2022New York2022-05-16 18:04385,871.20
9March2022New York2022-04-11 14:20494203.4
10Apri2022New York2022-05-17 17:17412691.43
11May2022New York2022-06-11 18:12275129.77
12
13
14February385871.2
Sheet1
Cell Formulas
RangeFormula
C14C14=SUM(((--(MAX((--(B14=$B$2:$B$11))*($G$2:$G$11))=$G$2:$G$11))*($J$2:$J$11)))

The formula =SUMPRODUCT((Data!$B$2:$B$1214=$B18)*(Data!$J$1:$P$1=C$2)*(Data!$F$2:$F$1214=$A18)*(Data!$J$2:$P$1214)) works great currently if the data is already cleaned up so that only the latest entry is in the array, but that's time consuming and I'm trying to make it easier going forward, so I'm trying to figure how to add to that formula to have it also select the MAX of the timestamps that satisfy the month, name, and revenue columns
 
Upvote 0
I thought the formula in POST 8 does that. What am I missing?
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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