# Optimize Formula

#### Leticia

##### New Member
Hi!
How can I optimize the following formula - putting it in just one Countifs?

COUNTIFS('D'!\$P:\$P;"OTRO";'D'!\$G:\$G;"<="&\$F\$4)+COUNTIFS('D'!\$G:\$G;"<="&\$F\$4;'D'!\$Q:\$Q;">"&\$F\$4)

Thank you!

### Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

#### jasonb75

##### Well-known Member
How can I optimize the following formula - putting it in just one Countifs?
If it isn't broken, why try to fix it?

There is nothing that you can do with that other than use a smaller count range, e.g to use a range that is big enough to include all of the data instead of the entire column.

#### Leticia

##### New Member
If it isn't broken, why try to fix it?

There is nothing that you can do with that other than use a smaller count range, e.g to use a range that is big enough to include all of the data instead of the entire column.
Because I am trying to use those formulas in a dynamic array, and I am not capable of putting them as a SUM inside the dynamic array. So I thought that maybe by mixing it, it would work.

#### jasonb75

##### Well-known Member
We can't give accurate full answers when you only ask half of the question. There might be something that can be done but there is no way of knowing what that might be without seeing how you want to use it (i.e. what you are attempting with the dynamic array). Most likely a data sample with the expected outcome will be necessary as well.

#### Leticia

##### New Member

The base formula is the following
=IF(\$G\$4="YES";(SUMIFS(TEST!\$F:\$F;TEST!\$C:\$C;"MISSSING";TEST!\$A:\$A;"<="&\$F\$4)+SUMIFS(TEST!\$F:\$F;TEST!\$E:\$E;"<>R.";TEST!\$E:\$E;"<>7250";TEST!\$A:\$A;"<="&\$F\$4;TEST!\$D:\$D;">"&\$F\$4;TEST!\$D:\$D;"<"&EDATE(\$F\$4;1)));SUMIFS(TEST!\$F:\$F;TEST!\$C:\$C;"MISSING";TEST!\$A:\$A;"<="&\$F\$4)+SUMIFS(TEST!\$F:\$F;TEST!\$A:\$A;"<="&\$F\$4;TEST!\$D:\$D;">"&\$F\$4))

F4=31/05/2021

DATABASE:
 DATE (A) CASE (B) CHECK (C) SOLUTION (D) TYPE (E) VALUE (F) 21/05/2021 P DONE 28/05/2021 4,85​ 21/05/2021 P DONE 02/06/2021 R. 8.893,96​ 22/05/2021 CA MISSING 400.000,00​ 22/05/2021 P DONE 28/05/2021 1,67​ 22/05/2021 CS DONE 02/06/2021 R. 355.791,00​ 22/05/2021 CS DONE 02/06/2021 R. 358,64​ 22/05/2021 CS DONE 02/06/2021 R. 358,64​ 22/05/2021 CS DONE 02/06/2021 R. 355.791,00​ 22/05/2021 CA DONE 15/06/2021 400.000,00​ 25/05/2021 CO DONE 28/05/2021 100.000,00​ 25/05/2021 P DONE 01/06/2021 5,25​ 25/05/2021 F DONE 02/06/2021 R. 7.300.000,00​ 26/05/2021 CA DONE 16/06/2021 1.718.000,00​ 26/05/2021 CO DONE 01/06/2021 422.832,98​ 26/05/2021 CO DONE 02/06/2021 R. 1.086,77​ 26/05/2021 CO DONE 02/06/2021 R. 1.086,77​ 26/05/2021 CO DONE 02/06/2021 R. 983,74​ 26/05/2021 CO DONE 03/06/2021 7250 9.244.707,41​ 26/05/2021 CO DONE 03/06/2021 7250 8.336.807,00​ 26/05/2021 CA DONE 15/06/2021 1.500.000,00​ 27/05/2021 CA MISSING 480.000,00​ 27/05/2021 P DONE 01/06/2021 15,75​ 27/05/2021 CA DONE 02/06/2021 R. 4.363,23​ 27/05/2021 CA DONE 02/06/2021 R. 4.363,23​ 27/05/2021 CA DONE 15/06/2021 400.000,00​ 28/05/2021 PF DONE 01/06/2021 0,97​ 28/05/2021 FV DONE 02/06/2021 R. 714.000,00​ 28/05/2021 CA DONE 15/06/2021 1.428.000,00​

I have done 3 dynamic arrays. One for each condition. (I would love to reduce it at least to two if possible)

=IFERROR(INDEX(SORTBY(CHOOSE({1\2};UNIQUE(FILTER(TEST!\$B:\$B;((TEST!\$C:\$C="MISSING")*(TEST!\$A:\$A<=\$F\$4))));SUMIFS(TEST!\$F:\$F;TEST!\$C:\$C;"MISSING";TEST!\$A:\$A;"<="&\$F\$4;TEST!\$B:\$B;UNIQUE(FILTER(TEST!\$B:\$B;((TEST!C:C="MISSING")*(TEST!\$A:\$A<=\$F\$4))))));SUMIFS(TEST!\$F:\$F;TEST!\$C:\$C;"MISSING";TEST!\$A:\$A;"<="&\$F\$4;TEST!\$B:\$B;UNIQUE(FILTER(TEST!\$B:\$B;((TEST!\$C:\$C="MISSING")*(TEST!\$A:\$A<=\$F\$4)))));-1);SEQUENCE(5;1;1);{1\2});"-")

=IFERROR(INDEX(SORTBY(CHOOSE({1\2};UNIQUE(FILTER(TEST!\$B:\$B;((TEST!\$D:\$D>\$F\$4)*(TEST!\$A:\$A<=\$F\$4))));SUMIFS(TEST!\$F:\$F;TEST!\$A:\$A;"<="&\$F\$4;TEST!\$D:\$D;">"&\$F\$4;TEST!\$B:\$B;UNIQUE(FILTER(TEST!\$B:\$B;((TEST!\$D:\$D>\$F\$4)*(TEST!\$A:\$A<=\$F\$4))))));SUMIFS(TEST!\$F:\$F;TEST!\$A:\$A;"<="&\$F\$4;TEST!\$D:\$D;">"&\$F\$4;TEST!\$B:\$B;UNIQUE(FILTER(TEST!\$B:\$B;((TEST!\$D:\$D>\$F\$4)*(TEST!\$A:\$A<=\$F\$4)))));-1);SEQUENCE(5;1;1);{1\2});"-")

=IFERROR(INDEX(SORTBY(CHOOSE({1\2};UNIQUE(FILTER(TEST!\$B:\$B;((TEST!\$D:\$D>\$F\$4)*(TEST!\$A:\$A<=\$F\$4)*(TEST!\$D:\$D<EDATE(\$F\$4;1))*(TEST!\$E:\$E<>"R.")*(TEST!\$E:\$E<>"7250"))));SUMIFS(TEST!\$F:\$F;TEST!\$A:\$A;"<="&\$F\$4;TEST!\$D:\$D;">"&\$F\$4;TEST!\$D:\$D;"<"&EDATE(\$F\$4;1);TEST!\$E:\$E;"<>R.";TEST!\$E:\$E;"<>7250";TEST!\$B:\$B;UNIQUE(FILTER(TEST!\$B:\$B;((TEST!\$D:\$D>\$F\$4)*(TEST!\$A:\$A<=\$F\$4)*(TEST!\$D:\$D<EDATE(\$F\$4;1))*(TEST!\$E:\$E<>"R.")*(TEST!\$E:\$E<>"7250"))))));SUMIFS(TEST!\$F:\$F;TEST!\$A:\$A;"<="&\$F\$4;TEST!\$D:\$D;">"&\$F\$4;TEST!\$D:\$D;"<"&EDATE(\$F\$4;1);TEST!\$E:\$E;"<>R.";TEST!\$E:\$E;"<>7250";TEST!\$B:\$B;UNIQUE(FILTER(TEST!\$B:\$B;((TEST!\$D:\$D>\$F\$4)*(TEST!\$A:\$A<=\$F\$4)*(TEST!\$D:\$D<EDATE(\$F\$4;1))*(TEST!\$E:\$E<>"R.")*(TEST!\$E:\$E<>"7250")))));-1);SEQUENCE(5;1;1);{1\2});"-")

#### Fluff

##### MrExcel MVP, Moderator
Do you have the LET function?

#### Leticia

##### New Member

Do you have the LET function?
No!

#### Fluff

##### MrExcel MVP, Moderator
In that case I would recommend you keep the three separate formulae.

#### Leticia

##### New Member
In that case I would recommend you keep the three separate formulae.

#### Fluff

##### MrExcel MVP, Moderator
Not sure what you mean.

Replies
3
Views
102
Replies
9
Views
255
Replies
6
Views
137
Replies
11
Views
194
Replies
4
Views
196

1,141,584
Messages
5,707,209
Members
421,498
Latest member
matinebi

### 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.

### Which adblocker are you using?

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

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