Benefit of asterisk vs nested IF in multiple IF criteria formulae

kcmuppet

Active Member
Joined
Nov 2, 2005
Messages
437
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm curious about whether there is a benefit in using a "*" to effectively separate / multiply criteria in IF functions vs nesting.

For example...

=INDEX(Table1[Color],MATCH(MAX( IF ( Table1[Item]="T-shirt" , IF (Table1[Size]="Large" , Table1[Time] ) ) ),Table1[Time],0))
vs
=INDEX(Table1[Color],MATCH(MAX( IF ( (Table1[Item]="T-shirt") * (Table1[Size]="Large"), Table1[Time] ) ) ,Table1[Time],0))

...seem to produce the same result, but is one any more efficient that another? Or is there some other relative benefit?

I have a table of ~8k rows and 45+ columns to search and ~35 of these formulae to populate another table, and sometimes 2-3 of these themselves subject to IF criteria in the same formula.
I have to stick to things that work for Excel 2010 so can't later alternatives.
 
Ahhh. Thanks for the explanation. I'm having trouble with AGGREGATE solutions. Excel doesn't accept that last formula in column I below, and when I tried to create an AGGREGATE solution to replace the MAXIFS and MAX(IF I'm not getting sensible results either.

I've included here some of the actual data instead of the screen grab. You're quite right through that there are sometimes Events in the data that are not preceded by an Event Type A (event though they should be irl), so I will need to have to deal with those errors.


Scratch Book1 (version 1).xlsb
BCDEFGHI
22NameEvent DateEventDate of latest Type AMAXIFS Date of first of this type of Event for this NameMAX ( IF Date of first of this type of Event for this NameAGGREGATE Date of first of this type of Event for this NameAGGREGATE This Event type since the last Type A, before the next Type A
23610669179701 Mar 18Event Type A01 Mar 1801 Mar 1801 Mar 18 
24610669179701 Mar 18Event Type D01 Mar 1801 Mar 1801 Mar 18 
25610669179723 Mar 18Event Type A23 Mar 1823 Mar 1823 Mar 1822 Jan 00
26610669179723 Mar 18Event Type D23 Mar 1823 Mar 1823 Mar 1822 Jan 00
27610669179728 Mar 18Event Type A28 Mar 1828 Mar 1828 Mar 1827 Jan 00
28610669179728 Mar 18Event Type D28 Mar 1828 Mar 1828 Mar 1827 Jan 00
29610669179703 Apr 18Event Type C28 Mar 1803 Apr 1803 Apr 18 
30610669179704 Apr 18Event Type B28 Mar 1804 Apr 1804 Apr 18 
31610669179712 Jul 18Event Type A12 Jul 1812 Jul 1812 Jul 1812 May 00
32610669179712 Jul 18Event Type D12 Jul 1812 Jul 1812 Jul 1812 May 00
33610669179716 Jul 18Event Type C12 Jul 1816 Jul 1816 Jul 1813 Apr 00
34610669179718 Jul 18Event Type B12 Jul 1818 Jul 1818 Jul 1814 Apr 00
35610669179720 Jul 18Event Type C12 Jul 1820 Jul 1820 Jul 1817 Apr 00
36610669179725 Jul 18Event Type B12 Jul 1825 Jul 1825 Jul 1821 Apr 00
37610669179727 Jul 18Event Type C12 Jul 1827 Jul 1827 Jul 1824 Apr 00
38610669179708 Aug 18Event Type C12 Jul 1808 Aug 1808 Aug 1806 May 00
39610669179708 Aug 18Event Type C12 Jul 1808 Aug 1808 Aug 1806 May 00
Sheet1
Cell Formulas
RangeFormula
F23:F39F23=IFERROR(1/(1/([@[Event Date]]-MAXIFS([Event],[Event],[@Event],[Name],[@Name],[Event Date],"<"&[@[Event Date]]))),"")
G23:G39G23=IFERROR(1/(1/([@[Event Date]]-MAX(IF( ([Event]=[@Event])* ([Name]=[@Name])* ([Event Date]<[@[Event Date]]), [Event])) )),"")
H23:H39H23=IFERROR([@[Event Date]]-1/(1/ AGGREGATE(15,6,[Event Date] /([Event]=[@Event]) /([Name]=[@Name]) /([Event Date]<[@[Event Date]]),1) ),"")


Thanks for the advice to update signature and profile. I guess the comment in my first post was easy to miss/confuse.
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I guess the comment in my first post was easy to miss
Yep, I checked to see if you had mentioned it anywhere before I said about it and still missed it :oops:

Looking at your data grab above, column H just needs to be reformatted to number / general. When you perform calculations on dates, excel incorrectly thinks it would be helpful to show the results as dates too.

I'm looking at your headers and getting lost as to what you actually mean with them, could you enter the expected results the same as you did with the earlier screen capture, then repost it as XL2BB so that I can test the formulas on the proper sample :)
 
Upvote 0
Hi thanks for bearing with me

Here is a version with last two column showing the results I'm trying to get using AGGREGATE in columns G and H manually entered:


Scratch Book2.xlsx
BCDEFGH
22NameEvent DateEventDate of latest Type AMAX ( IF Date of first of this type of Event for this NameSame as Column G using AGGREGATERunning count of this type of event for this Name since the last Type A using AGGREGATE
23610669179701 Mar 18Type A01 Mar 1801 Mar 1801 Mar 181
24610669179701 Mar 18Type D01 Mar 1801 Mar 1801 Mar 181
25610669179723 Mar 18Type A23 Mar 1823 Mar 1823 Mar 181
26610669179723 Mar 18Type D23 Mar 1823 Mar 1823 Mar 181
27610669179728 Mar 18Type A28 Mar 1828 Mar 1828 Mar 181
28610669179728 Mar 18Type D28 Mar 1828 Mar 1828 Mar 181
29610669179703 Apr 18Type C28 Mar 1803 Apr 1803 Apr 181
30610669179704 Apr 18Type B28 Mar 1804 Apr 1804 Apr 181
31610669179712 Jul 18Type A12 Jul 1812 Jul 1812 Jul 181
32610669179712 Jul 18Type D12 Jul 1812 Jul 1812 Jul 181
33610669179716 Jul 18Type C12 Jul 1816 Jul 1816 Jul 181
34610669179718 Jul 18Type B12 Jul 1818 Jul 1818 Jul 181
35610669179720 Jul 18Type C12 Jul 1820 Jul 1820 Jul 182
36610669179725 Jul 18Type B12 Jul 1825 Jul 1825 Jul 182
37610669179727 Jul 18Type C12 Jul 1827 Jul 1827 Jul 183
38610669179708 Aug 18Type C12 Jul 1808 Aug 1808 Aug 184
39610669179708 Aug 18Type C12 Jul 1808 Aug 1808 Aug 185
Sheet1
Cell Formulas
RangeFormula
F23:F39F23=IFERROR(1/(1/([@[Event Date]]-MAX(IF(([Event]=[@Event])*([Name]=[@Name])*([Event Date]<[@[Event Date]]),[Event])))),"")
 
Upvote 0
With sincere apologies the previously posted outputs were wrong!

Below is a corrected version with last two column showing the results I'm trying to get using AGGREGATE in columns G and H manually entered. It also seems that what I had previously in F "Date of first of this type of Event for this Name" was also wrong. I left the wrong formulae producing the right result in the first row


Scratch Book2.xlsx
BCDEFGHI
22NameEvent DateEventDate of latest Type ADate of first of this type of Event for this NameDate of first of this type of Event for this Name since the last Type A using MAX( IFSame as Column G using AGGREGATERunning count of this type of event for this Name since the last Type A using AGGREGATE
23610669179701 Mar 18Type A01 Mar 1801 Mar 1801 Mar 1801 Mar 181
24610669179701 Mar 18Type D01 Mar 1801 Mar 1801 Mar 1801 Mar 181
25610669179723 Mar 18Type A23 Mar 1801 Mar 1823 Mar 1823 Mar 181
26610669179723 Mar 18Type D23 Mar 1801 Mar 1824 Mar 1824 Mar 181
27610669179728 Mar 18Type A28 Mar 1801 Mar 1828 Mar 1828 Mar 181
28610669179728 Mar 18Type D28 Mar 1801 Mar 1828 Mar 1828 Mar 181
29610669179703 Apr 18Type C28 Mar 1803 Apr 1828 Mar 1828 Mar 181
30610669179704 Apr 18Type B28 Mar 1804 Apr 1828 Mar 1828 Mar 181
31610669179712 Jul 18Type A12 Jul 1801 Mar 1812 Jul 1812 Jul 181
32610669179712 Jul 18Type D12 Jul 1801 Mar 1812 Jul 1812 Jul 181
33610669179716 Jul 18Type C12 Jul 1803 Apr 1812 Jul 1812 Jul 181
34610669179718 Jul 18Type B12 Jul 1804 Apr 1818 Jul 1818 Jul 181
35610669179720 Jul 18Type C12 Jul 1803 Apr 1820 Jul 1820 Jul 182
36610669179725 Jul 18Type B12 Jul 1804 Apr 1818 Jul 1818 Jul 182
37610669179727 Jul 18Type C12 Jul 1803 Apr 1820 Jul 1820 Jul 183
38610669179708 Aug 18Type C12 Jul 1803 Apr 1820 Jul 1820 Jul 184
39610669179708 Aug 18Type C12 Jul 1803 Apr 1820 Jul 1820 Jul 185
Sheet1
Cell Formulas
RangeFormula
F23F23=IFERROR(1/(1/([@[Event Date]]-MAX(IF(([Event]=[@Event])*([Name]=[@Name])*([Event Date]<[@[Event Date]]),[Event])))),"")
G23,G27:G28G23=IFERROR(1/(1/([@[Event Date]]- MAX(IF( ([Event]=[@Event])* ([Name]=[@Name])* ([Event Date]<[@[Event Date]])* ([Event Date]<[@[Date of latest Type A]]), [Event])))),"")
 
Upvote 0
I'm making progress and now have some of the results I'm looking for using the AGGREGATE function suggested:

I ended up using AGGREGATE's options 14 & 15 LARGE & SMALL because when I tried MIN & MAX with the same criteria, I get a #Value errors usinge the same criteria, which I don't understand.

I also don't understand though why my count isn't working in column H.

Scratch Book2.xlsx
BCDEFGHI
22NameEvent DateEventDate of latest Type A so farDate of first of this type of Event for this NameDate of first of this type of Event for this Name since the last Type ARunning count of this type of event for this Name since the last Type A using AGGREGATEExpected value for Column H
23610669179701 Mar 18Event Type A01 Mar 1801 Mar 1801 Mar 1811
24610669179701 Mar 18Event Type D01 Mar 1801 Mar 1801 Mar 18#VALUE!1
25610669179723 Mar 18Event Type A23 Mar 1801 Mar 1823 Mar 1811
26610669179723 Mar 18Event Type D23 Mar 1801 Mar 1823 Mar 18#VALUE!1
27610669179728 Mar 18Event Type A28 Mar 1801 Mar 1828 Mar 1811
28610669179728 Mar 18Event Type D28 Mar 1801 Mar 1828 Mar 18#VALUE!1
29610669179703 Apr 18Event Type C28 Mar 1803 Apr 1803 Apr 18#VALUE!1
30610669179704 Apr 18Event Type B28 Mar 1804 Apr 1804 Apr 18#VALUE!1
31610669179712 Jul 18Event Type A12 Jul 1801 Mar 1812 Jul 1811
32610669179712 Jul 18Event Type D12 Jul 1801 Mar 1812 Jul 18#VALUE!1
33610669179716 Jul 18Event Type C12 Jul 1803 Apr 1816 Jul 18#VALUE!1
34610669179718 Jul 18Event Type B12 Jul 1804 Apr 1818 Jul 18#VALUE!1
35610669179720 Jul 18Event Type C12 Jul 1803 Apr 1816 Jul 18#VALUE!2
36610669179725 Jul 18Event Type B12 Jul 1804 Apr 1818 Jul 18#VALUE!2
37610669179727 Jul 18Event Type C12 Jul 1803 Apr 1816 Jul 18#VALUE!3
38610669179708 Aug 18Event Type C12 Jul 1803 Apr 1816 Jul 18#VALUE!4
39610669179708 Aug 18Event Type C12 Jul 1803 Apr 1816 Jul 18#VALUE!5
Sheet1
Cell Formulas
RangeFormula
E23:E39E23=AGGREGATE(14,6,[Event Date] /(([Name]=[@Name])* ([Event]="Event Type A")* ([Event Date]<=[@[Event Date]]) ),1)
F23:F39F23=AGGREGATE(15,6,[Event Date] /(([Name]=[@Name])* ([Event]=[@Event]) ),1)
G23:G39G23=IF([@Event]="Event Type A",[@[Event Date]],AGGREGATE(15,6,[Event Date] /(([Name]=[@Name])* ([Event]=[@Event])* ([Event Date]>=[@[Date of latest Type A so far]]) ),1))
H23:H39H23=IF([@Event]="Event Type A",1, AGGREGATE(2,6,[Event] /(([Name]=[@Name])* ([Event]=[@Event])* ([Event Date]>[@[Date of latest Type A so far]]) )))



Ref Post Number 10

I found a spare comma before <=
Excel Formula:
=IF([@[Event]]="Event Type A","",IFERROR([@[Event Date]]-1/(1/AGGREGATE(14,6,[Event Date]/([Event]="Event Type A")/([Name]=[@[Name]])/([Event Date],<=[@[Event Date]]),1)),""))
:

Taking that into consideration, along with the need for a 2010 compatible formula, I think that this should work.
Excel Formula:
=IF([@[Event]]="Event Type A","",IFERROR([@[Event Date]]-1/(1/AGGREGATE(14,6,[Event Date]/([Event]="Event Type A")/([Name]=[@[Name]])/([Event Date],<=[@[Event Date]]),1)),""))

I think it should have been:
Excel Formula:
=IF([@[Event]]="Event Type A","",IFERROR([@[Event Date]]-1/(1/AGGREGATE(14,6,[Event Date]/([Event]="Event Type A")/([Name]=[@[Name]])/([Event Date]<=[@[Event Date]]),1)),""))

but actually although it's accepted now as a valid formula it's returning only "".
 
Last edited:
Upvote 0
I've made a couple of adjustments to the formulas, I don't think that there is any problem with doing it the way that you have with columns E:G. I've seen others use the same but I prefer to use division all the way through, that way I know that there will be no erroneous zero results if I forget to enclose the whole array in an extra pair of parenthesis.

With reference to the #VALUE! errors, the rows that show a valid result are the ones where the result is shown without aggregate being calculated, the array method only works with specific function numbers, count is not one of them. Take a look at my replies in this thread for more info on this Use of AGGREGATE

Hopefully I haven't missed anything in the grab below.
Book1
BCDEFGHI
22NameEvent DateEventDate of latest Type A so farDate of first of this type of Event for this NameDate of first of this type of Event for this Name since the last Type ARunning count of this type of event for this Name since the last Type A using AGGREGATEDays since last Type A
23610669179701 March 2018Event Type A01 March 201801 March 201801 March 20181 
24610669179701 March 2018Event Type D01 March 201801 March 201801 March 201810
25610669179723 March 2018Event Type A23 March 201801 March 201823 March 20181 
26610669179723 March 2018Event Type D23 March 201801 March 201823 March 201810
27610669179728 March 2018Event Type A28 March 201801 March 201828 March 20181 
28610669179728 March 2018Event Type D28 March 201801 March 201828 March 201810
29610669179703 April 2018Event Type C28 March 201803 April 201803 April 201816
30610669179704 April 2018Event Type B28 March 201804 April 201804 April 201817
31610669179712 July 2018Event Type A12 July 201801 March 201812 July 20181 
32610669179712 July 2018Event Type D12 July 201801 March 201812 July 201810
33610669179716 July 2018Event Type C12 July 201803 April 201816 July 201814
34610669179718 July 2018Event Type B12 July 201804 April 201818 July 201816
35610669179720 July 2018Event Type C12 July 201803 April 201816 July 201828
36610669179725 July 2018Event Type B12 July 201804 April 201818 July 2018213
37610669179727 July 2018Event Type C12 July 201803 April 201816 July 2018315
38610669179708 August 2018Event Type C12 July 201803 April 201816 July 2018527
39610669179708 August 2018Event Type C12 July 201803 April 201816 July 2018527
Sheet1
Cell Formulas
RangeFormula
E23:E39E23=AGGREGATE(14,6,[Event Date] /([Name]=[@Name])/([Event]="Event Type A")/([Event Date]<=[@[Event Date]]),1)
F23:F39F23=AGGREGATE(15,6,[Event Date] /([Name]=[@Name])/([Event]=[@Event]),1)
G23:G39G23=IF([@Event]="Event Type A",[@[Event Date]],AGGREGATE(15,6,[Event Date] /([Name]=[@Name])/([Event]=[@Event])/([Event Date]>=[@[Date of latest Type A so far]]),1))
H23:H39H23=COUNTIFS([Name],[@Name],[Event],[@Event],[Date of latest Type A so far],[@[Date of latest Type A so far]],[Event Date],"<="&[@[Event Date]])
I23:I39I23=IF([@Event]="Event Type A","",IFERROR([@[Event Date]]-1/(1/AGGREGATE(14,6,[Event Date]/([Event]="Event Type A")/([Name]=[@Name])/([Event Date]<=[@[Event Date]]),1)),""))
 
Upvote 0
Well Jason, Thank you very much. I've been using Excel for >25 years and today, thanks to your extended help and patience, is the first time I ever used AGGREGATE
...and it keeps me from having to wrestle with Power Pivot & DAX for a little while longer!
 
Upvote 0
Just pondering the example data again in post 16 ... How would I adjust the formula for column H currently:
Excel Formula:
=COUNTIFS([Name],[@Name],[Event],[@Event],[Date of latest Type A so far],[@[Date of latest Type A so far]],[Event Date],"<="&[@[Event Date]])
...to keep a running count even when two events happen on the same day? - i.e. so that the value in H38 would be 4, not 5?
 
Upvote 0
oops, I missed that one when I compared the results. That needs to use a dynamic / expanding range which can get a bit messy with table names.
I'll have another look at it but it might not get chance to test and post the formula until late saturday.
 
Upvote 0
That needs to use a dynamic / expanding range which can get a bit messy with table names.
I've added the formula below using table names and normal ranges so that you can see the difference. Note that the normal range formula will not work correctly in a table. It looks fine here but it doesn't expand correctly when you add new rows.
Book1
BCDEFG
22NameEvent DateEventDate of latest Type A so farRunning count of this type of event for this Name since the last Type AWithout table refs
23610669179701/03/2018Event Type A01/03/201811
24610669179701/03/2018Event Type D01/03/201811
25610669179723/03/2018Event Type A23/03/201811
26610669179723/03/2018Event Type D23/03/201811
27610669179728/03/2018Event Type A28/03/201811
28610669179728/03/2018Event Type D28/03/201811
29610669179703/04/2018Event Type C28/03/201811
30610669179704/04/2018Event Type B28/03/201811
31610669179712/07/2018Event Type A12/07/201811
32610669179712/07/2018Event Type D12/07/201811
33610669179716/07/2018Event Type C12/07/201811
34610669179718/07/2018Event Type B12/07/201811
35610669179720/07/2018Event Type C12/07/201822
36610669179725/07/2018Event Type B12/07/201822
37610669179727/07/2018Event Type C12/07/201833
38610669179708/08/2018Event Type C12/07/201844
39610669179708/08/2018Event Type C12/07/201855
Sheet1
Cell Formulas
RangeFormula
E23:E39E23=AGGREGATE(14,6,[Event Date] /([Name]=[@Name])/([Event]="Event Type A")/([Event Date]<=[@[Event Date]]),1)
F23:F39F23=COUNTIFS(Table1[[#Headers],[Name]]:INDEX([Name],ROW([@Name])-ROW(Table1[[#Headers],[Name]])),[@Name], Table1[[#Headers],[Event]]:INDEX([Event],ROW([@Event])-ROW(Table1[[#Headers],[Event]])),[@Event], Table1[[#Headers],[Date of latest Type A so far]]:INDEX([Date of latest Type A so far],ROW([@[Date of latest Type A so far]])-ROW(Table1[[#Headers],[Date of latest Type A so far]])),[@[Date of latest Type A so far]], Table1[[#Headers],[Event Date]]:INDEX([Event Date],ROW([@[Event Date]])-ROW(Table1[[#Headers],[Event Date]])),"<="&[@[Event Date]])
G23:G39G23=COUNTIFS(B$23:B23,B23,D$23:D23,D23,E$23:E23,E23,C$23:C23,"<="&C23)
 
Upvote 0
Solution

Forum statistics

Threads
1,215,506
Messages
6,125,197
Members
449,214
Latest member
mr_ordinaryboy

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