Optimize Formula

Leticia

New Member
Joined
Jun 9, 2021
Messages
37
Office Version
  1. 365
Platform
  1. Windows
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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
13,543
Office Version
  1. 365
Platform
  1. Windows
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
Joined
Jun 9, 2021
Messages
37
Office Version
  1. 365
Platform
  1. Windows
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
Joined
Dec 30, 2008
Messages
13,543
Office Version
  1. 365
Platform
  1. Windows
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
Joined
Jun 9, 2021
Messages
37
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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/2021PDONE28/05/2021
4,85​
21/05/2021PDONE02/06/2021R.
8.893,96​
22/05/2021CAMISSING
400.000,00​
22/05/2021PDONE28/05/2021
1,67​
22/05/2021CSDONE02/06/2021R.
355.791,00​
22/05/2021CSDONE02/06/2021R.
358,64​
22/05/2021CSDONE02/06/2021R.
358,64​
22/05/2021CSDONE02/06/2021R.
355.791,00​
22/05/2021CADONE15/06/2021
400.000,00​
25/05/2021CODONE28/05/2021
100.000,00​
25/05/2021PDONE01/06/2021
5,25​
25/05/2021FDONE02/06/2021R.
7.300.000,00​
26/05/2021CADONE16/06/2021
1.718.000,00​
26/05/2021CODONE01/06/2021
422.832,98​
26/05/2021CODONE02/06/2021R.
1.086,77​
26/05/2021CODONE02/06/2021R.
1.086,77​
26/05/2021CODONE02/06/2021R.
983,74​
26/05/2021CODONE03/06/20217250
9.244.707,41​
26/05/2021CODONE03/06/20217250
8.336.807,00​
26/05/2021CADONE15/06/2021
1.500.000,00​
27/05/2021CAMISSING
480.000,00​
27/05/2021PDONE01/06/2021
15,75​
27/05/2021CADONE02/06/2021R.
4.363,23​
27/05/2021CADONE02/06/2021R.
4.363,23​
27/05/2021CADONE15/06/2021
400.000,00​
28/05/2021PFDONE01/06/2021
0,97​
28/05/2021FVDONE02/06/2021R.
714.000,00​
28/05/2021CADONE15/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)
1625418419380.png

=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
Joined
Jun 12, 2014
Messages
62,470
Office Version
  1. 365
Platform
  1. Windows
Do you have the LET function?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,470
Office Version
  1. 365
Platform
  1. Windows
In that case I would recommend you keep the three separate formulae.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,470
Office Version
  1. 365
Platform
  1. Windows
Not sure what you mean.
 

Forum statistics

Threads
1,141,480
Messages
5,706,638
Members
421,460
Latest member
Taamrak

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
Top