Sumifs for greatest date and other criteria

martinli

New Member
Joined
Jul 25, 2018
Messages
4
Hi,

I have a data set with multiple columns. See below.

ABCDEFG
OrderRcvr-OrderMonthYearPct.
332673901822653720151.00901822653
332673901822653520160.803326731.84
332673901822653220180.04
332673901822656520160.04
332673901822657520160.04
332673901822658520160.04
332673901822720520160.04

<colgroup><col span="5"><col><col></colgroup><tbody>
</tbody>

<colgroup><col span="5"><col><col></colgroup><tbody></tbody>

<colgroup><col span="5"><col><col></colgroup><tbody></tbody>
I have a formula on G4 =SUMIFS($E:$E,$A:$A,F4,$B:$B,G3) that returns 1.84 as an example. However I want it to return only the greatest Month/Year Combo. In this case 2, 2018 for a total of 0.04. How Can I incorporate a max function within a sumif or is there an alternative way.

Thanks in advance!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Welcome to the forum.

Try this in G4:

=INDEX(E3:E9,MATCH(MAX(IF(A3:A9=F4,IF(B3:B9=G3,D3:D9*100+C3:C9))),IF(A3:A9=F4,IF(B3:B9=G3,D3:D9*100+C3:C9)),0))

confirmed with Control+Shift+Enter.
 
Upvote 0
Hello Eric,

Just curious to know, why do we need to multiply date by 100 ? and why is it not picking if we do not multiply, or else the formula works perfectly
 
Last edited:
Upvote 0
What we're doing here:

D3:D9*100+C3:C9

is multiplying the year by 100 and adding the month, for each row in the range. So a month of 7 and a year of 2018 gives us 201807, and a month of 3 and a year of 2019 gives us 201903. So when we compare 201807 and 201903, we can see that 201903 is more than 201807, so it comes last. If you create a whole list of those numbers, and use the MAX function, you'll get the largest date.

If you don't multiply by 100, you'll get 7 + 2018 = 2025 and 3 + 2019 = 2022, and if we compare 2025 and 2022, we'd get the wrong idea of which one comes first.
 
Upvote 0

Forum statistics

Threads
1,215,607
Messages
6,125,818
Members
449,262
Latest member
hideto94

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