SOLVED

Help - How to count occurrences in a range that returns true or false

%3CLINGO-SUB%20id%3D%22lingo-sub-2276369%22%20slang%3D%22en-US%22%3EHelp%20-%20How%20to%20count%20occurrences%20in%20a%20range%20that%20returns%20true%20or%20false%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2276369%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EOur%20company%20just%20switched%20the%20platform%20from%20Google%20to%20MS%20so%20I've%20been%20struggling%20to%20convert%20certain%20formulas%20to%20Excel%2C%20which%20I%20haven't%20used%20for%20many%20years%20now.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20here's%20the%20problem%3A%3C%2FP%3E%3CP%3EI%20have%20two%20tabs%20-%20the%20first%20one%20contains%20a%20sprint%20number%2C%20the%20second%20one%20a%20Start%20Date%2C%20and%20the%20third%20one%20an%20End%20Date%20for%20the%20sprint.%3C%2FP%3E%3CP%3EThe%20other%20tab%20has%20a%20table%20with%20many%20columns%20where%20column%20T%20contains%20a%20date.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20goal%20is%20to%20count%20the%20number%20of%20tickets%20(or%20rows)%20from%20the%20table%20where%20column%20T%20is%20between%20the%20Start%20and%20End%20Dates%20from%20the%20first%20tab.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENote%3A%20each%20sprint%20has%20its%20own%20table%20on%20a%20separate%20tab%2C%20hence%20why%20I'm%20using%20INDIRECT%20to%20compose%20the%20name%20of%20the%20tab%20I'm%20looking%20for.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20different%20approaches%20using%20COUNTIF%2C%20COUNTA%2C%20FILTER%2C%20and%20PRODSUM%20but%20I%20always%20get%20some%20kind%20of%20error%20that%20I%20was%20able%20to%20find%20the%20root%20cause%20for.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20help%20-%20sample%20spreadsheet%20is%20attached.%3C%2FP%3E%3CP%3EThank%20you!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2276369%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2276561%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20-%20How%20to%20count%20occurrences%20in%20a%20range%20that%20returns%20true%20or%20false%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2276561%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1024126%22%20target%3D%22_blank%22%3E%40ragomes1972%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20have%20made%20your%20move%20to%20MS%20at%20an%20interesting%20time.%26nbsp%3B%20Excel%20development%20is%20now%20being%20influenced%20by%20academics%20of%20international%20reputation%20in%20the%20area%20of%20functional%20programming.%26nbsp%3B%20Whereas%20Excel%20had%20started%20to%20lag%20Sheets%2C%20there%20are%20now%20features%20that%20make%20the%20application%20behave%20more%20like%20a%20software%20development%20platform%20than%20something%20for%20'end%20users%20in%20denial%20of%20the%20fact%20that%20they%20are%20programming'.%26nbsp%3B%20For%20example%2C%20for%20me%2C%20formulas%20normally%20begin%3C%2FP%3E%3CP%3E%3D%20LET(%3C%2FP%3E%3CP%3Eand%26nbsp%3B%3C%2FP%3E%3CP%3E%3D%20LAMBDA(x%2Cy%2C%3C%2FP%3E%3CP%3Eis%20beginning%20to%20creep%20in.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3D%20LET(%0A%20%20%20%20type%2C%20%20%20%20%20%20INDIRECT(%22Sprint%22%26amp%3BSprint%26amp%3B%22%5BIssue%20Type%5D%22)%2C%0A%20%20%20%20component%2C%20INDIRECT(%22Sprint%22%26amp%3BSprint%26amp%3B%22%5BComponents%5D%22)%2C%0A%20%20%20%20submit%2C%20%20%20%20INDIRECT(%22Sprint%22%26amp%3BSprint%26amp%3B%22%5BSubmitDate%5D%22)%2C%0A%20%20%20%20bugCount%2C%20%20COUNTIFS(type%2C%22Bug%22%2Ccomponent%2C%22%22%2Csubmit%2C%22%26gt%3B%3D%22%26amp%3BStartDate%2Csubmit%2C%22%26lt%3B%3D%22%26amp%3BEndDate)%2C%0A%20%20bugCount)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EPretty%20much%20all%20calculation%20is%20array%20formula%20and%20anything%20really%20data-heavy%20would%20be%20Power%20Query.%26nbsp%3B%20I%20will%20know%20I%20have%20passed%20the%20point%20of%20no%20return%20when%20I%20hear%20myself%20say%20%22Oh%2C%20I%20nearly%20forgot%2C%20Excel%20will%20also%20run%20those%20legacy%20spreadsheet%20things!%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECaveat.%20These%20are%20just%20my%20opinions%3B%20as%20yet%2C%20far%20from%20mainstream.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2276446%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20-%20How%20to%20count%20occurrences%20in%20a%20range%20that%20returns%20true%20or%20false%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2276446%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1024126%22%20target%3D%22_blank%22%3E%40ragomes1972%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20SUMPRODUCT%20formula%2C%20don't%20use%20entire%20columns%2C%20but%20finite%20ranges%20instead%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3DSUMPRODUCT((INDIRECT(%22'JQL%20-%20Sprint%20%22%26amp%3BA3%26amp%3B%22'!B2%3AB100%22)%3D%22Bug%22)*(INDIRECT(%22'JQL%20-%20Sprint%20%22%26amp%3BA3%26amp%3B%22'!U2%3AU100%22)%3D%22%22)*(INDIRECT(%22'JQL%20-%20Sprint%20%22%26amp%3BA3%26amp%3B%22'!T2%3AT100%22)%26gt%3BB3)*(INDIRECT(%22'JQL%20-%20Sprint%20%22%26amp%3BA3%26amp%3B%22'!T2%3AT100%22)%3CC3%3E%3C%2FC3%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2276426%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20-%20How%20to%20count%20occurrences%20in%20a%20range%20that%20returns%20true%20or%20false%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2276426%22%20slang%3D%22en-US%22%3E%3C%2FLINGO-BODY%3E%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1024126%22%20target%3D%22_blank%22%3E%40ragomes1972%3C%2FA%3E%3C%2FP%3E%0A%3CP%3EThe%20criteria_range%20arguments%20for%20COUNTIFS%20cannot%20be%20expressions.%20They%20can%20only%20be%20ranges.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20D3%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3DCOUNTIFS(INDIRECT(%22'JQL%20-%20Sprint%20%22%26amp%3B%20A3%26amp%3B%22'!B%3AB%22)%2C%22Bug%22%2CINDIRECT(%22'JQL%20-%20Sprint%20%22%26amp%3BA3%26amp%3B%22'!U%3AU%22)%2C%20%22%22%2CINDIRECT(%22'JQL%20-%20Sprint%20%22%26amp%3BA3%26amp%3B%22'!T%3AT%22)%2C%22%26gt%3B%22%26amp%3BB3%2CINDIRECT(%22'JQL%20-%20Sprint%20%22%26amp%3BA3%26amp%3B%22'!T%3AT%22)%2C%22%26lt%3B%22%26amp%3BC3)%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi,

Our company just switched the platform from Google to MS so I've been struggling to convert certain formulas to Excel, which I haven't used for many years now.

 

So here's the problem:

I have two tabs - the first one contains a sprint number, the second one a Start Date, and the third one an End Date for the sprint.

The other tab has a table with many columns where column T contains a date.

 

My goal is to count the number of tickets (or rows) from the table where column T is between the Start and End Dates from the first tab.

 

Note: each sprint has its own table on a separate tab, hence why I'm using INDIRECT to compose the name of the tab I'm looking for. 

 

I tried different approaches using COUNTIF, COUNTA, FILTER, and PRODSUM but I always get some kind of error that I was able to find the root cause for.

 

Please help - sample spreadsheet is attached.

Thank you!

3 Replies

@ragomes1972

The criteria_range arguments for COUNTIFS cannot be expressions. They can only be ranges.

 

In D3:

 

=COUNTIFS(INDIRECT("'JQL - Sprint "& A3&"'!B:B"),"Bug",INDIRECT("'JQL - Sprint "&A3&"'!U:U"), "",INDIRECT("'JQL - Sprint "&A3&"'!T:T"),">"&B3,INDIRECT("'JQL - Sprint "&A3&"'!T:T"),"<"&C3)

best response confirmed by ragomes1972 (Occasional Contributor)
Solution

@ragomes1972 

In the SUMPRODUCT formula, don't use entire columns, but finite ranges instead:

 

=SUMPRODUCT((INDIRECT("'JQL - Sprint "&A3&"'!B2:B100")="Bug")*(INDIRECT("'JQL - Sprint "&A3&"'!U2:U100")="")*(INDIRECT("'JQL - Sprint "&A3&"'!T2:T100")>B3)*(INDIRECT("'JQL - Sprint "&A3&"'!T2:T100")<C3))

@ragomes1972 

You have made your move to MS at an interesting time.  Excel development is now being influenced by academics of international reputation in the area of functional programming.  Whereas Excel had started to lag Sheets, there are now features that make the application behave more like a software development platform than something for 'end users in denial of the fact that they are programming'.  For example, for me, formulas normally begin

= LET(

and 

= LAMBDA(x,y,

is beginning to creep in.

= LET(
    type,      INDIRECT("Sprint"&Sprint&"[Issue Type]"),
    component, INDIRECT("Sprint"&Sprint&"[Components]"),
    submit,    INDIRECT("Sprint"&Sprint&"[SubmitDate]"),
    bugCount,  COUNTIFS(type,"Bug",component,"",submit,">="&StartDate,submit,"<="&EndDate),
  bugCount)

Pretty much all calculation is array formula and anything really data-heavy would be Power Query.  I will know I have passed the point of no return when I hear myself say "Oh, I nearly forgot, Excel will also run those legacy spreadsheet things!"

 

Caveat. These are just my opinions; as yet, far from mainstream.