NTIMES(reference,[number],[blanks],[output_orientation],[exclude_types],[include_types],[replace_with],[if_empty])
reference
Required. Specifies the function input and can be a cell, range, or array.
number
Optional. instructs the function to return values that occur at this specified number of times and can be any natural number.
blanks
Optional. Specifies how the blanks in the input will be treated and takes two arguments: 0 or omitted or FALSE, for counting all four blank types as equivalent; and 1 or TRUE or any number other than 0, for counting each of the four blank types separately.
output_orientation
Optional. Specifies the orientation of the function output and takes two arguments: 0 or omitted or FALSE, for horizontal (default) output; and 1 or TRUE or any number other than 0, for vertical output.
exclude_types
Optional. Specifies the type(s) of data that can be excluded from the main output and takes one or more of twenty-six arguments: 1, for number; 2, for text; 3, for blank; 4, for logical; 16, for error; 31, for real blank; 32, for formula blank; 33, for space blank; 34, for pasted blank; 41, for TRUE; 42, for FALSE; 161, for #NULL! error; 162, for #DIV/0! error; 163, for #VALUE! error; 164, for #REF! error; 165, for #NAME? error; 166, for #NUM! error; 167, for #N/A error; 168, for #GETTING_DATA error; 169, for #SPILL! error; 1610, for #CONNECT! error; 1611, for #BLOCKED! error; 1612, for #UNKNOWN! error; 1613, for #FIELD! error; 1614, for #CALC! error; and 1619, for #PYTHON! error.
include_types
Optional. Specifies the type(s) of data that can be included in the main output and takes one or more of twenty-six arguments: 1, for number; 2, for text; 3, for blank; 4, for logical; 16, for error; 31, for real blank; 32, for formula blank; 33, for space blank; 34, for pasted blank; 41, for TRUE; 42, for FALSE; 161, for #NULL! error; 162, for #DIV/0! error; 163, for #VALUE! error; 164, for #REF! error; 165, for #NAME? error; 166, for #NUM! error; 167, for #N/A error; 168, for #GETTING_DATA error; 169, for #SPILL! error; 1610, for #CONNECT! error; 1611, for #BLOCKED! error; 1612, for #UNKNOWN! error; 1613, for #FIELD! error; 1614, for #CALC! error; and 1619, for #PYTHON! error.
replace_with
Optional. Specifies a single entry of any desired data type (i.e. number, text, blank, logical, or error) that can be used to replace any entries that were either directly excluded via the exclude_types parameter or indirectly excluded via the include_types parameter.
if_empty
Optional. Specifies a single entry of any desired data type (i.e. number, text, blank, logical, or error) that can be displayed as the main function output if the output is empty.

NTIMES returns the values that occur at the specified number of times with full control over data types(s) inclusion/exclusion/replacement

Rnkhch

Well-known Member
Joined
Apr 28, 2018
Messages
578
Office Version
  1. 365
Platform
  1. Windows
NTIMES returns the values that occur at the specified number of times with full control over data types(s) inclusion/exclusion/replacement

(The code is modular (as all my other functions) allowing for easy reusing/swapping/optimizing over time. See all the modules below, after the description)


NTIMES takes eight parameters, one required and seven optional, as follows:

A) The first parameter, required, specifies the function input and can be a cell, range, or array

B) The second parameter, optional, instructs the function to return values that occur at this specified number of times and can be any natural number (i.e. 1 or greater) or omitted to imply 1

Note that leaving this parameter omitted or setting it to 1 makes the function equivalent (and more straightforward) to UNIQUE(reference,,1) where the "exactly_once" parameter is turned on

Note that this argument structure which takes only natural numbers is accomplished by my PLSN module shown below

C) The third parameter, optional, is a logical switch and specifies how the blanks in the input will be treated, as follows:
0 or omitted or FALSE, indicates that all four types of blanks, i.e. 31, 32, 33, and 34, (see the latest update of XTYPE) have the same overall value, and therefore, their total count will be compared against the number specified in the second parameter above
1 or TRUE or any number other than 0, indicates that the four types of blanks will be counted separately and then compared against the number specified in the second parameter above

Note that this argument structure matches the Excel's native way of handling on/off arguments for parameters and is accomplished by my PLSL module shown below (applies to the fourth parameter below as well)

D) The fourth parameter, optional, is a logical switch and specifies the orientation of the function output, as follows:
0 or omitted or FALSE, for horizontal (default) output
1 or TRUE or any number other than 0, for vertical output

Note that unlike the native UNIQUE function, NTIMES linearizes the output. If you need the output to have a desired number of rows or columns, feel free to use my PROCESS function

E) The fifth parameter, optional, specifies the type(s) of data that can be excluded from the main output and takes one or more of twenty-six arguments:
1, for number
2, for text
3, for blank
4, for logical
16, for error
31, for real blank
32, for formula blank
33, for space blank
34, for pasted blank
41, for TRUE
42, for FALSE
161, for #NULL! error
162, for #DIV/0! error
163, for #VALUE! error
164, for #REF! error
165, for #NAME? error
166, for #NUM! error
167, for #N/A error
168, for #GETTING_DATA error
169, for #SPILL! error
1610, for #CONNECT! error
1611, for #BLOCKED! error
1612, for #UNKNOWN! error
1613, for #FIELD! error
1614, for #CALC! error
1619, for #PYTHON! error

Note that if you need to enter more than one argument, you need to use the array brackets "{}" such as {1,3} for excluding numbers and blanks or {2,4,16} for excluding texts, logicals, and errors; see the attached XL2BB examples (the number of types permutations is huge; I have only shown a few examples); this parameter as well as the next (include_types) allow for a remarkable level of flexibility and full resolution for managing data types in the function output

Note that excluding type(s) may cause the output spill to auto-shrink, if the output contains the specified type(s). If you don't want the output to auto-shrink, you need to put a blank ("") in the seventh parameter, i.e. replace_with, as described below in section G

Note that excluding type(s) that are not available in the output will have no effect on the output

F) The sixth parameter, optional, specifies the type(s) of data that can be included in the main output and takes one or more of twenty-six arguments, exactly like the fifth parameter in section E above

Note that both exclude_types and include_types cannot be used simultaneously

Note that using include_types (unless all types are included as by {1,2,3,4,16} for example) will also cause the main output spill to auto-shrink. Again, if you don't want the output to auto-shrink, you need to put a blank ("") in the seventh parameter, i.e. replace_with, as described below in section G

Note that including type(s) that are not available in the output will lead to an "empty" #CALC! error with the message that "Empty arrays are not supported"

G) The seventh parameter, optional, specifies a single entry of any desired data type (i.e. number, text, blank, logical, or error) that can be used to replace any entries that were either directly excluded via the exclude_types parameter or indirectly excluded via the include_types parameter

Note that if including type(s) leads to an empty output, then use of replace_with will cause the specified element to appear for the entire range of the output prior to the inclusion

H) The eighth parameter, optional, specifies a single entry of any desired data type (i.e. number, text, blank, logical, or error) that can be displayed as the main function output if the output is empty, i.e. #CALC! with the message "Empty arrays are not supported"

(You can download my template from the link in my signature below, which makes it easier to obtain/test the functions compared to pasting from the text/XL2BB or entering the functions manually)


NTIMES
Excel Formula:
=LAMBDA(reference,[number],[blanks],[output_orientation],[exclude_types],[include_types],[replace_with],[if_empty],
   LET(
      r,IF(
         LEN(TRIM(reference))>0,
         reference,
         ""
      ),
      n,PLSN(number),
      b,PLSL(blanks),
      o,PLSL(output_orientation),
      x,XTYPE(reference,3),
      j,JAS(
         r,
         JAR(reference,b),
         x,
         b
      ),
      v,INDEX(j,3)=n,
      k,FILTER(INDEX(j,1),v),
      l,JAI(
         SWITCH(JAL(exclude_types,include_types,replace_with),
            0,k,
            1,JAC(
               exclude_types,
               include_types,
               replace_with,
               k,
               FILTER(INDEX(j,4),v))
            ),
         if_empty
      ),
      IF(o,TRANSPOSE(l),l)
   )
)

JAR (counting core of NTIMES)
Excel Formula:
=LAMBDA(reference,blanks,
   LET(
      r,reference,
      c,LEN(TRIM(r)),
      IF(
         ISERROR(r),
         LET(
            x,ERROR.TYPE(r),
            MAP(x,LAMBDA(a,ST1F0(x=a)))
         ),
         IF(
            c>0,
            IF(
               r=FALSE,
               MAP(r,LAMBDA(a,ST1F0(TEXT(r,10)="FALSE"))),
               MAP(r,LAMBDA(a,ST1F0(r=a)))
            ),
            IF(
               blanks,
               LET(
                  x,IF(
                     c=0,
                     IF(
                        ISBLANK(r),
                        31,
                        IF(
                           ISFORMULA(r),
                           32,
                           IF(LEN(r)>0,33,34))
                        ),
                     ""
                  ),
                  MAP(x,LAMBDA(a,ST1F0(a=x)))
               ),
               LET(
                  x,IF(c=0,1,0),
                  MAP(x,LAMBDA(a,ST1F0(a=x)))
               )
            )
         )
      )
   )
)

JAS (filter core for NTIMES)
Excel Formula:
=LAMBDA(reference,counts,types,blanks,
   LET(
      r,reference,
      c,SEQUENCE(,ROWS(r)*COLUMNS(r)),
      i,TOROW(r),
      j,TOROW(counts),
      z,TOROW(types),
      t,{31,32,33,34},
      k,JAI(
         UNIQUE(
            FILTER(
               i,
               ISERROR(MATCH(z,t,0))
            ),
            1
         ),
         0
      ),
      p,IFERROR(
         MATCH(
            IFERROR(k,ERROR.TYPE(k)),
            IFERROR(i,ERROR.TYPE(i)),
            0
         ),
         0
      ),
      a,IF(
         blanks,
         HSTACK(
            IFERROR(
               UNIQUE(
                  FILTER(
                     i,
                     NOT(ISERROR(MATCH(z,{31},0)))
                  ),
                  1
               ),
               0
            ),
            IFERROR(
               UNIQUE(
                  FILTER(
                     i,
                     NOT(ISERROR(MATCH(z,{32},0)))
                  ),
                  1
               ),
               0
            ),
            IFERROR(
               UNIQUE(
                  FILTER(
                     i,
                     NOT(ISERROR(MATCH(z,{33},0)))
                  ),
                  1
               ),
               0
            ),
            IFERROR(
               UNIQUE(
                  FILTER(
                     i,
                     NOT(ISERROR(MATCH(z,{34},0)))
                  ),
                  1
               ),
               0
            )
         ),
         IFERROR(
            UNIQUE(
               FILTER(
                  i,
                  NOT(ISERROR(MATCH(z,t,0)))
               ),
               1
            ),
            0
         )
      ),
      y,HSTACK(k,a),
      u,HSTACK(
         p,
         LET(
            x,IFERROR(MATCH(t,z,0),0),
            IF(
               blanks,
               x,
               SMALL(IF(x>0,x),1)
            )
         )
      ),
      q,MATCH(u,c,0),
      v,INDEX(j,1,q),
      w,LET(
         x,INDEX(z,1,q),
         IF(
            blanks,
            x,
            IF(
               ISERROR(MATCH(x,t,0)),
               x,
               3
            )
         )
      ),
      SORT(
         CHOOSECOLS(
            VSTACK(y,u,v,w),
            FILTER(
               SEQUENCE(,COLUMNS(u)),
               u>0
            )
         ),
         2,
         1,
         1
      )
   )
)

XERROR.TYPE (posted separately)

XTYPE (posted separately)

AllTypes
Excel Formula:
={1,2,3,4,16,31,32,33,34,41,42,161,162,163,164,165,166,167,168,169,1610,1611,1612,1613,1614,1619}

IO (shortened form of ISOMITTED)
Excel Formula:
=LAMBDA(parameter,
   ISOMITTED(parameter)
)

NIO [shortened form of NOT(ISOMITTED)]
Excel Formula:
=LAMBDA(parameter,
   NOT(ISOMITTED(parameter))
)

PLS (stands for "parameter limit, single")
(Returns the parameter if it is a single entry (not blank or error) and #N/A otherwise)
(Causes the function to crash to a single #N/A if the incorrect parameter is entered [either the wrong type or more than a single entry in array brackets "{}"])
Excel Formula:
=LAMBDA(parameter,
   INDEX(
      IF(
         OR(JAN(parameter),JAO(parameter),JAP(parameter)),
         NA(),
         parameter
      ),
      1
   )
)

PLSL (stands for "parameter limit, single logical")
(Returns 1 if the parameter is a single TRUE entry; 0 if the parameter is a single FALSE entry or is omitted; and #N/A otherwise)
(Causes the function to crash to a single #N/A if incorrect parameters are entered [either anything not logically evaluable or more than a single entry in array brackets "{}"]))
Excel Formula:
=LAMBDA([parameter],
   IF(
      IO(parameter),
      0,
      IF(
         JAN(parameter),
         NA(),
         LET(
            p,INDEX(parameter,1),
            IF(
               ISERROR(p),
               NA(),
               T1F0(p)
            )
         )
      )
   )
)

PLSN (stands for "parameter limit, single natural")
(Returns the parameter if it is a single natural number and #N/A otherwise)
(Causes the function to crash to a single #N/A if incorrect parameters are entered)
Excel Formula:
=LAMBDA(parameter,
   INDEX(
      IF(
         OR(JAN(parameter),JAO(parameter),JAP(parameter)),
         NA(),
         IF(
            ISNUMBER(parameter),
            IF(
               OR(MOD(parameter,1),parameter=0),
               NA(),
               parameter
            ),
            NA()
         )
      ),
      1
   )
)

PO0 (Returns 0 if the parameter is omitted and the parameter itself otherwise)
Excel Formula:
=LAMBDA([parameter],
   IF(IO(parameter),0,parameter)
)

T1F0 (Returns 1 if the reference is TRUE, 0 if the reference is FALSE, and #N/A otherwise)
Excel Formula:
=LAMBDA(expression,
   IF(
      ISNUMBER(expression)+ISLOGICAL(expression),
      IF(expression,1,0),
      NA()
   )
)

ST1F0 [Returns the sum of all TRUE (1) and FALSE (0) elements of the reference (counting all elements that cannot be logically evaluated as 0)]
Excel Formula:
=LAMBDA(reference,
   SUM(T1F0(IFERROR(reference,0)))
)

JAB (returns a number greater than or equal to 1 (i.e. TRUE) if the reference has the specified data type(s) and 0 (i.e. FALSE) otherwise)
Excel Formula:
=LAMBDA(types,advanced_types_array,
   IF(
      SUM(T1F0(ISERROR(MATCH(types,AllTypes,0)))),
      NA(),
      LET(
         basic_types_array,SWITCH(advanced_types_array,1,1,2,2,31,3,32,3,33,3,34,3,41,4,42,4,"","",16),
         MAP(
            advanced_types_array,
            LAMBDA(a,OR(a=types))
         )+
         MAP(
            basic_types_array,
            LAMBDA(a,OR(a=types))
         )
      )
   )
)

JAC (module for 1D (FILTER-based) "exclude_types/include_types/replace_with" with auto-shrink)
Excel Formula:
=LAMBDA(exclude_types,include_types,replace_with,main_array,advanced_types_array,
   LET(
      d,IF(IO(include_types),exclude_types,include_types),
      x,JAB(d,advanced_types_array),
      IF(
         IO(replace_with),
         FILTER(
            main_array,
            IF(IO(include_types),NOT(x),x)
         ),
         IF(
            IO(include_types),
            IF(x,replace_with,main_array),
            IF(x,main_array,replace_with)
         )
      )
)
)

JAI (module for "if_empty")
Excel Formula:
=LAMBDA(operation,if_empty,
   IF(
      JAN(if_empty),
      NA(),
      LET(
         e,IF(
            ISERROR(operation),
            IF(ERROR.TYPE(operation)=14,1,0),
            0
         ),
         f,IF(
            ISERROR(ROWS(operation)*COLUMNS(operation)),
            1,
            0
         ),
         IF(
            e+f=2,
            IF(IO(if_empty),operation,if_empty),
            operation
         )
      )
   )
)

JAL (switch for "include_types/exclude_types")
Excel Formula:
=LAMBDA(exclude_types,include_types,replace_with,
   IF(
      JAN(replace_with),
      NA(),
      IFS(
         AND(IO(exclude_types),IO(include_types),IO(replace_with)),0,
         OR(AND(IO(include_types),NIO(exclude_types)),AND(NIO(include_types),IO(exclude_types))),1
      )
   )
)

JAN Returns TRUE if the reference is an array (i.e. is not a single element or is not omitted) and FALSE otherwise [simplified form of ISARRAY])
Excel Formula:
=LAMBDA([reference],
   LET(
      r,IFERROR(IF(reference="","",reference),""),
      IF(
         IO(reference),
         FALSE,
         IF(ROWS(r)*COLUMNS(r)>1,TRUE,FALSE)
      )
   )
)

JAO (Returns TRUE if the reference contains at least one error and FALSE otherwise [simplified form of ISERRORS])
Excel Formula:
=LAMBDA(reference,
   IF(
      IO(reference),
      FALSE,
      IF(SUM(IF(ISERROR(reference),1,0)),TRUE,FALSE)
   )
)

JAP (Returns TRUE if the reference contains at least one blank and FALSE otherwise [simplified form of ISBLANKS])
Excel Formula:
=LAMBDA(reference,
   IF(
      IO(reference),
      NA(),
      IF(SUM(IF(IFERROR(reference,0)="",1,0)),TRUE,FALSE)
   )
)

NTIMES.xlsx
ABCDEFGHIJKLMNOPQRS
1 
2#CALC!basic types
3types(advanced)XTYPE(C4:H7,3)1dt:NUMBER
423bookTRUE#DIV/0!note12411623122dt:TEXT
5FALSE 56.8 23#N/A423313211673dt:BLANK
6107bookTRUE7.53413124114dt:LOGICAL
7#VALUE!100 book#DIV/0!16331133216216dt:ERROR
8
9countsJAR(C4:H7,0)types(basic)XTYPE(C4:H7,2)advanced types
10blank types having the same value23227112416321dt:NUMBER
1117172143131162dt:TEXT
1271732131324131dt:BLANK_REAL
131717321631321632dt:BLANK_FORMULA
1433dt:BLANK_SPACE
15countsJAR(C4:H7,1)34dt:BLANK_PASTED
16distinct blank types23223141dt:LOGICAL_TRUE
1712112142dt:LOGICAL_FALSE
18113321161dt:ERROR_NULL!
19131232162dt:ERROR_DIV/0!
20163dt:ERROR_VALUE!
21164dt:ERROR_REF!
22numberblanksoutput165dt:ERROR_NAME?
231omittednoteFALSE56.8#N/A1077.5#VALUE!100166dt:ERROR_NUM!
2410noteFALSE56.8#N/A1077.5#VALUE!100167dt:ERROR_N/A
2511noteFALSE56.8#N/A1077.5#VALUE!100168dt:ERROR_GETTING_DATA
262omitted23TRUE#DIV/0!169dt:ERROR_SPILL!
272023TRUE#DIV/0!1610dt:ERROR_CONNECT!
282123TRUE#DIV/0!1611dt:ERROR_BLOCKED!
293omittedbook1612dt:ERROR_UNKNOWN!
3030book1613dt:ERROR_FIELD!
3131book1614dt:ERROR_CALC!
324omitted#CALC!1619dt:ERROR_PYTHON!
3340#CALC!
3441#CALC!
355omitted#CALC!
3650#CALC!
3751#CALC!
386omitted#CALC!
3960#CALC!
4061#CALC!
417omitted 
4270 
4371#CALC!
44
45numberblanksexclude_typesinclude_typesreplace_withoutput
46101omittedomittednoteFALSE#N/A#VALUE!
47112omittedomittedFALSE56.8#N/A1077.5#VALUE!100
48104omittedomittednote56.8#N/A1077.5#VALUE!100
491116omittedomittednoteFALSE56.81077.5100
501041omittedomittednoteFALSE56.8#N/A1077.5#VALUE!100
511142omittedomittednote56.8#N/A1077.5#VALUE!100
5210162omittedomittednoteFALSE56.8#N/A1077.5#VALUE!100
5311163omittedomittednoteFALSE56.8#N/A1077.5100
5410167omittedomittednoteFALSE56.81077.5#VALUE!100
5511168omittedomittednoteFALSE56.8#N/A1077.5#VALUE!100
56103omittedomittednoteFALSE56.8#N/A1077.5#VALUE!100
57113omittedomittednoteFALSE56.8#N/A1077.5#VALUE!100
581031omittedomittednoteFALSE56.8#N/A1077.5#VALUE!100
591131omittedomittednoteFALSE56.8#N/A1077.5#VALUE!100
601032omittedomittednoteFALSE56.8#N/A1077.5#VALUE!100
611132omittedomittednoteFALSE56.8#N/A1077.5#VALUE!100
621033omittedomittednoteFALSE56.8#N/A1077.5#VALUE!100
631133omittedomittednoteFALSE56.8#N/A1077.5#VALUE!100
641034omittedomittednoteFALSE56.8#N/A1077.5#VALUE!100
651134omittedomittednoteFALSE56.8#N/A1077.5#VALUE!100
66
67numberblanksexclude_typesinclude_typesreplace_withoutput
6810omitted1omitted56.81077.5100
6911omitted2omittednote
7010omitted4omittedFALSE
7111omitted16omitted#N/A#VALUE!
7210omitted41omitted#CALC!
7311omitted42omittedFALSE
7410omitted162omitted#CALC!
7511omitted163omitted#VALUE!
7610omitted167omitted#N/A
7711omitted168omitted#CALC!
7810omitted3omitted#CALC!
7911omitted3omitted 
8010omitted31omitted#CALC!
8111omitted31omitted#CALC!
8210omitted32omitted#CALC!
8311omitted32omitted 
8410omitted33omitted#CALC!
8511omitted33omitted#CALC!
8610omitted34omitted#CALC!
8711omitted34omitted 
88
89numberblanksexclude_typesinclude_typesreplace_withoutput
9010omitted1REPLACEDREPLACEDREPLACED56.8REPLACED1077.5REPLACED100
91212omittedREPLACED23TRUE#DIV/0!
9210omitted4REPLACEDREPLACEDFALSEREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACED
933116omittedREPLACEDbook
9410omitted41REPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACED
952142omittedREPLACED23TRUE#DIV/0!
9610omitted162REPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACED
9731163omittedREPLACEDbook
9810omitted167REPLACEDREPLACEDREPLACEDREPLACED#N/AREPLACEDREPLACEDREPLACEDREPLACED
9921168omittedREPLACED23TRUE#DIV/0!
10010omitted3REPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACED
101313omittedREPLACEDbookREPLACED
10210omitted31REPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACED
1032131omittedREPLACED23TRUE#DIV/0!
10410omitted32REPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACED
1053132omittedREPLACEDbook
10610omitted33REPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACED
1072133omittedREPLACED23TRUE#DIV/0!REPLACED
10810omitted34REPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACEDREPLACED
1093134omittedREPLACEDbook
110
NTIMES
Cell Formulas
RangeFormula
B1,F5B1=IF(1,"")
C2C2=LAMBDA(reference,[number],[blanks],[output_orientation],[exclude_types],[include_types],[replace_with],[if_empty],LET(r,IF(LEN(TRIM(reference))>0,reference,""),n,PLSN(number),b,PLSL(blanks),o,PLSL(output_orientation),x,XTYPE(reference,3),j,SORT(JAS(r,JAR(reference,b),x,b),2,1,1),v,INDEX(j,3)=n,k,FILTER(INDEX(j,1),v),l,JAI(SWITCH(JAL(exclude_types,include_types,replace_with),0,k,1,JAC(exclude_types,include_types,replace_with,k,FILTER(INDEX(j,4),v))),if_empty),IF(o,TRANSPOSE(l),l)))
J4:O7J4=XTYPE(C4:H7,3)
F4,H7F4=1/0
H5H5=#N/A
C10:H13C10=JAR(C4:H7,0)
J10:O13J10=XTYPE(C4:H7,2)
C16:H19C16=JAR(C4:H7,1)
D23:K23D23=NTIMES($C$4:$H$7,1)
D24:K24D24=NTIMES($C$4:$H$7,1,0)
D25:M25D25=NTIMES($C$4:$H$7,1,1)
D26:F26D26=NTIMES($C$4:$H$7,2)
D27:F27D27=NTIMES($C$4:$H$7,2,0)
D28:G28D28=NTIMES($C$4:$H$7,2,2)
D29D29=NTIMES($C$4:$H$7,3)
D30D30=NTIMES($C$4:$H$7,3,0)
D31:E31D31=NTIMES($C$4:$H$7,3,3)
D32D32=NTIMES($C$4:$H$7,4)
D33D33=NTIMES($C$4:$H$7,4,0)
D34D34=NTIMES($C$4:$H$7,4,4)
D35D35=NTIMES($C$4:$H$7,5)
D36D36=NTIMES($C$4:$H$7,5,0)
D37D37=NTIMES($C$4:$H$7,5,5)
D38D38=NTIMES($C$4:$H$7,6)
D39D39=NTIMES($C$4:$H$7,6,0)
D40D40=NTIMES($C$4:$H$7,6,6)
D41D41=NTIMES($C$4:$H$7,7)
D42D42=NTIMES($C$4:$H$7,7,0)
D43D43=NTIMES($C$4:$H$7,7,7)
G46:J46G46=NTIMES($C$4:$H$7,1,0,,1)
G47:O47G47=NTIMES($C$4:$H$7,1,1,,2)
G48:M48G48=NTIMES($C$4:$H$7,1,0,,4)
G49:N49G49=NTIMES($C$4:$H$7,1,1,,16)
G50:N50G50=NTIMES($C$4:$H$7,1,0,,41)
G51:O51G51=NTIMES($C$4:$H$7,1,1,,42)
G52:N52G52=NTIMES($C$4:$H$7,1,0,,162)
G53:O53G53=NTIMES($C$4:$H$7,1,1,,163)
G54:M54G54=NTIMES($C$4:$H$7,1,0,,167)
G55:P55G55=NTIMES($C$4:$H$7,1,1,,168)
G56:N56G56=NTIMES($C$4:$H$7,1,0,,3)
G57:N57G57=NTIMES($C$4:$H$7,1,1,,3)
G58:N58G58=NTIMES($C$4:$H$7,1,0,,31)
G59:P59G59=NTIMES($C$4:$H$7,1,1,,31)
G60:N60G60=NTIMES($C$4:$H$7,1,0,,32)
G61:O61G61=NTIMES($C$4:$H$7,1,1,,32)
G62:N62G62=NTIMES($C$4:$H$7,1,0,,33)
G63:P63G63=NTIMES($C$4:$H$7,1,1,,33)
G64:N64G64=NTIMES($C$4:$H$7,1,0,,34)
G65:O65G65=NTIMES($C$4:$H$7,1,1,,34)
G68:J68G68=NTIMES($C$4:$H$7,1,0,,,1)
G69G69=NTIMES($C$4:$H$7,1,1,,,2)
G70G70=NTIMES($C$4:$H$7,1,0,,,4)
G71:H71G71=NTIMES($C$4:$H$7,1,1,,,16)
G72G72=NTIMES($C$4:$H$7,1,0,,,41)
G73G73=NTIMES($C$4:$H$7,1,1,,,42)
G74G74=NTIMES($C$4:$H$7,1,0,,,162)
G75G75=NTIMES($C$4:$H$7,1,1,,,163)
G76G76=NTIMES($C$4:$H$7,1,0,,,167)
G77G77=NTIMES($C$4:$H$7,1,1,,,168)
G78G78=NTIMES($C$4:$H$7,1,0,,,3)
G79:H79G79=NTIMES($C$4:$H$7,1,1,,,3)
G80G80=NTIMES($C$4:$H$7,1,0,,,31)
G81G81=NTIMES($C$4:$H$7,1,1,,,31)
G82G82=NTIMES($C$4:$H$7,1,0,,,32)
G83G83=NTIMES($C$4:$H$7,1,1,,,32)
G84G84=NTIMES($C$4:$H$7,1,0,,,33)
G85G85=NTIMES($C$4:$H$7,1,1,,,33)
G86G86=NTIMES($C$4:$H$7,1,0,,,34)
G87G87=NTIMES($C$4:$H$7,1,1,,,34)
G90:N90G90=NTIMES($C$4:$H$7,1,0,,,1,"REPLACED")
G91:J91G91=NTIMES($C$4:$H$7,2,1,,2,,"REPLACED")
G92:N92G92=NTIMES($C$4:$H$7,1,0,,,4,"REPLACED")
G93:H93G93=NTIMES($C$4:$H$7,3,1,,16,,"REPLACED")
G94:N94G94=NTIMES($C$4:$H$7,1,0,,,41,"REPLACED")
G95:J95G95=NTIMES($C$4:$H$7,2,1,,42,,"REPLACED")
G96:N96G96=NTIMES($C$4:$H$7,1,0,,,162,"REPLACED")
G97:H97G97=NTIMES($C$4:$H$7,3,1,,163,,"REPLACED")
G98:N98G98=NTIMES($C$4:$H$7,1,0,,,167,"REPLACED")
G99:J99G99=NTIMES($C$4:$H$7,2,1,,168,,"REPLACED")
G100:N100G100=NTIMES($C$4:$H$7,1,0,,,3,"REPLACED")
G101:H101G101=NTIMES($C$4:$H$7,3,1,,3,,"REPLACED")
G102:N102G102=NTIMES($C$4:$H$7,1,0,,,31,"REPLACED")
G103:J103G103=NTIMES($C$4:$H$7,2,1,,31,,"REPLACED")
G104:N104G104=NTIMES($C$4:$H$7,1,0,,,32,"REPLACED")
G105:H105G105=NTIMES($C$4:$H$7,3,1,,32,,"REPLACED")
G106:N106G106=NTIMES($C$4:$H$7,1,0,,,33,"REPLACED")
G107:J107G107=NTIMES($C$4:$H$7,2,1,,33,,"REPLACED")
G108:N108G108=NTIMES($C$4:$H$7,1,0,,,34,"REPLACED")
G109:H109G109=NTIMES($C$4:$H$7,3,1,,34,,"REPLACED")
Dynamic array formulas.
 
Upvote 0
I noticed that I had missed the "less than" sign, i.e. "<" in the code for PLSN, so here is the correction:

PLSN
Excel Formula:
=LAMBDA(parameter,
   INDEX(
      IF(
         OR(JAN(parameter),JAO(parameter),JAP(parameter)),
         NA(),
         IF(
            ISNUMBER(parameter),
            IF(
               OR(MOD(parameter,1),parameter<=0),
               NA(),
               parameter
            ),
            NA()
         )
      ),
      1
   )
)
 
Updated code:
1) Fixes the bug that caused the function to output an error if the "number" parameter was left blank. Now leaving it blank will imply number 1 as originally intended
2) Massively improves the speed of the function through a new simplified core (JAS). It was brought to my attention that large selections of cells were too slow to process. Indeed when I tested A1:JJJ29, the function got stuck in processing for 10 minutes when I escaped it. The new core took less than 2 seconds to process the same range. The old counting JAR core was MAP-based which was the cause of the slow-down. The new core is MMULT-based. Also, this update removes the JAR and combines counting and filtering into the one simplified JAS

NTIMES
Excel Formula:
=LAMBDA(reference,[number],[blanks],[output_orientation],[exclude_types],[include_types],[replace_with],[if_empty],
   LET(
      r,IF(LEN(TRIM(reference))>0,reference,""),
      n,IF(IO(number),1,PLSN(number)),
      b,PLSL(blanks),
      o,PLSL(output_orientation),
      x,XTYPE(reference,3),
      j,JAS(r,x,b),
      v,INDEX(j,2)=n,
      k,FILTER(INDEX(j,1),v),
      l,JAI(
         SWITCH(JAL(exclude_types,include_types,replace_with),
            0,k,
            1,JAC(
               exclude_types,
               include_types,
               replace_with,
               k,
               FILTER(INDEX(j,3),v)
            )
         ),
         if_empty
      ),
      IF(o,TRANSPOSE(l),l)
   )
)

JAS (core for NTIMES)
Excel Formula:
=LAMBDA(reference,types,blanks,
   LET(
      r,reference,
      c,SEQUENCE(,ROWS(r)*COLUMNS(r)),
      i,TOROW(r),
      z,TOROW(types),
      t,{31,32,33,34},
      k,JAI(
         UNIQUE(
            FILTER(i,ISERROR(MATCH(z,t,0))),
            1
         ),
         0
      ),
      p,IFERROR(
         MATCH(
            IFERROR(k,ERROR.TYPE(k)),
            IFERROR(i,ERROR.TYPE(i)),
            0
         ),
         0
      ),
      a,IF(
         blanks,
         HSTACK(
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{31},0)))),1),0),
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{32},0)))),1),0),
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{33},0)))),1),0),
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{34},0)))),1),0)
         ),
         IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,t,0)))),1),0)
      ),
      y,HSTACK(k,a),
      u,HSTACK(
         p,
         LET(
            x,IFERROR(MATCH(t,z,0),0),
            IF(
               blanks,
               x,
               SMALL(IF(x>0,x),1)
            )
         )
      ),
      q,MATCH(u,c,0),
      w,LET(
         x,INDEX(z,1,q),
         IF(
            blanks,
            x,
            IF(ISERROR(MATCH(x,t,0)),x,3)
         )
      ),
      b,CHOOSEROWS(
         SORT(
            CHOOSECOLS(
               VSTACK(y,u,w),
               FILTER(SEQUENCE(,COLUMNS(u)),u>0)
            ),
            2,
            1,
            1
         ),
         {1,3}
      ),
      d,INDEX(b,1),
      g,INDEX(b,2),
      e,TOROW(
         IF(
            ISERROR(r),
            MATCH(ERROR.TYPE(r),ERROR.TYPE(d),0),
            IF(
               blanks,
               IF(
                  LEN(r)=0,
                  MATCH(types,g,0),
                  MATCH(r,d,0)
               ),
               MATCH(r,d,0)
            )
         )
      ),
      f,SEQUENCE(MAX(e)),
      h,MMULT(
         --(e=f),
         SEQUENCE(COUNTA(e),1,1,0)
      ),
      VSTACK(d,TRANSPOSE(h),g)
   )
)
 
Updated code: Improves function speed by swapping the latest MMULT-based core with a new FREQUENCY-based core. The difference is only in the variable "h" at the end of the code where MMULT(--(e=f),SEQUENCE(COUNTA(e),1,1,0)) is substituted by CHOOSEROWS(FREQUENCY(e,f),f) as follows:

JAS (core for NTIMES)
Excel Formula:
=LAMBDA(reference,types,blanks,
   LET(
      r,reference,
      c,SEQUENCE(,ROWS(r)*COLUMNS(r)),
      i,TOROW(r),
      z,TOROW(types),
      t,{31,32,33,34},
      k,JAI(
         UNIQUE(
            FILTER(i,ISERROR(MATCH(z,t,0))),
            1
         ),
         0
      ),
      p,IFERROR(
         MATCH(
            IFERROR(k,ERROR.TYPE(k)),
            IFERROR(i,ERROR.TYPE(i)),
            0
         ),
         0
      ),
      a,IF(
         blanks,
         HSTACK(
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{31},0)))),1),0),
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{32},0)))),1),0),
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{33},0)))),1),0),
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{34},0)))),1),0)
         ),
         IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,t,0)))),1),0)
      ),
      y,HSTACK(k,a),
      u,HSTACK(
         p,
         LET(
            x,IFERROR(MATCH(t,z,0),0),
            IF(
               blanks,
               x,
               SMALL(IF(x>0,x),1)
            )
         )
      ),
      q,MATCH(u,c,0),
      w,LET(
         x,INDEX(z,1,q),
         IF(
            blanks,
            x,
            IF(ISERROR(MATCH(x,t,0)),x,3)
         )
      ),
      b,CHOOSEROWS(
         SORT(
            CHOOSECOLS(
               VSTACK(y,u,w),
               FILTER(SEQUENCE(,COLUMNS(u)),u>0)
            ),
            2,
            1,
            1
         ),
         {1,3}
      ),
      d,INDEX(b,1),
      g,INDEX(b,2),
      e,TOROW(
         IF(
            ISERROR(r),
            MATCH(ERROR.TYPE(r),ERROR.TYPE(d),0),
            IF(
               blanks,
               IF(
                  LEN(r)=0,
                  MATCH(types,g,0),
                  MATCH(r,d,0)
               ),
               MATCH(r,d,0)
            )
         )
      ),
      f,SEQUENCE(MAX(e)),
      h,CHOOSEROWS(
         FREQUENCY(e,f),
         f
      ),
      VSTACK(d,TRANSPOSE(h),g)
   )
)
 
Updated code:
1) Adds the capability to specify multiple numbers (instead of only one) in the "number" parameter, so now any values that occur at the specified number(s) of times can be returned. Note that if multiple numbers are specified, they need to be entered within array brackets and separated by commas per native syntax (e.g. {3,5,2})
2) Fixes the bug that caused the empty #CALC! error, rather than the #N/A error, to be displayed if a non-natural number was specified in the "number" parameter
3) the update in number #1 needed swapping the PLSN (single natural number) module with the PLMN (multiple natural numbers) and adding JBA

NTIMES
Excel Formula:
=LAMBDA(reference,[number],[blanks],[output_orientation],[exclude_types],[include_types],[replace_with],[if_empty],
   LET(
      r,IF(LEN(TRIM(reference))>0,reference,""),
      n,JBA(IF(IO(number),1,PLMN(number))),
      b,PLSL(blanks),
      o,PLSL(output_orientation),
      x,XTYPE(reference,3),
      j,JAS(r,x,b),
      v,IF(ISERROR(MATCH(INDEX(j,2),n,0)),FALSE,TRUE),
      k,FILTER(INDEX(j,1),v),
      l,JAI(
         SWITCH(JAL(exclude_types,include_types,replace_with),
            0,k,
            1,JAC(
               exclude_types,
               include_types,
               replace_with,
               k,
               FILTER(INDEX(j,3),v)
            )
         ),
         if_empty
      ),
      IF(JAO(n),NA(),IF(o,TRANSPOSE(l),l))
   )
)

PLMN (stands for "parameter limit, multiple natural")
(Returns the parameter if it is at least one natural number (not blank or error) and #N/A otherwise)
(Causes the function to crash to a single #N/A if the incorrect argument is entered, i.e. wrong data type or non-natural numbers)
Excel Formula:
=LAMBDA(parameter,
   LET(
      o,IF(
         OR(JAO(parameter),JAP(parameter)),
         NA(),
         IF(
            ISNUMBER(parameter),
            IF(
               OR(MOD(parameter,1),parameter<=0),
               NA(),
               parameter
            ),
            NA()
         )
      ),
      IF(
         ST1F0(ISERROR(o)),
         NA(),
         o
      )
   )
)

JAS (core for NTIMES)
Excel Formula:
=LAMBDA(reference,types,blanks,
   LET(
      r,reference,
      c,SEQUENCE(,ROWS(r)*COLUMNS(r)),
      i,TOROW(r),
      z,TOROW(types),
      t,{31,32,33,34},
      k,JAI(
         UNIQUE(
            FILTER(i,ISERROR(MATCH(z,t,0))),
            1
         ),
         0
      ),
      p,IFERROR(
         MATCH(
            IFERROR(k,ERROR.TYPE(k)),
            IFERROR(i,ERROR.TYPE(i)),
            0
         ),
         0
      ),
      a,IF(
         blanks,
         HSTACK(
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{31},0)))),1),0),
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{32},0)))),1),0),
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{33},0)))),1),0),
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{34},0)))),1),0)
         ),
         IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,t,0)))),1),0)
      ),
      y,HSTACK(k,a),
      u,HSTACK(
         p,
         LET(
            x,IFERROR(MATCH(t,z,0),0),
            IF(
               blanks,
               x,
               SMALL(IF(x>0,x,0),1)
            )
         )
      ),
      q,MATCH(u,c,0),
      w,LET(
         x,INDEX(z,1,q),
         IF(
            blanks,
            x,
            IF(ISERROR(MATCH(x,t,0)),x,3)
         )
      ),
      b,CHOOSEROWS(
         SORT(
            CHOOSECOLS(
               VSTACK(y,u,w),
               FILTER(SEQUENCE(,COLUMNS(u)),u>0)
            ),
            2,
            1,
            1
         ),
         {1,3}
      ),
      d,INDEX(b,1),
      g,INDEX(b,2),
      e,TOROW(
         IF(
            ISERROR(r),
            MATCH(ERROR.TYPE(r),ERROR.TYPE(d),0),
            IF(
               blanks,
               IF(
                  LEN(r)=0,
                  MATCH(types,g,0),
                  MATCH(r,d,0)
               ),
               MATCH(r,d,0)
            )
         )
      ),
      f,SEQUENCE(MAX(e)),
      h,CHOOSEROWS(
         FREQUENCY(e,f),
         f
      ),
      VSTACK(d,TRANSPOSE(h),g)
   )
)

JBA (inserts single values into array brackets "{}")
Excel Formula:
=LAMBDA(reference[if_omitted],
   IF(
      IO(reference),
      if_omitted,
      LET(
         r,reference,
         IF(
            AND(COLUMNS(IFERROR(r,""))=1,ISERROR(r)),
            CHOOSECOLS(CHOOSE({1,2},r,r),1),
            FILTER(r,SEQUENCE(,COLUMNS(r)))
         )
      )
   )
)
 
Updated code:
1) Renames the "number" parameter to "numbers" as multiple numbers can be specified since the last update
1) Adds the capability to specify comparative numbers, i.e. "less than", "less than or equal", "greater than", or "greater than or equal", in the "numbers" parameter, so now there is a remarkable level of flexibility for specifying any count of numbers and/or any count of comparative numbers
3) optimizes code

In this section of the text, I'm providing an update to the "section B" in the original post which explains the "numbers" parameter and its new capabilities (for all other sections, check the original post):

-----------------------
B) The second parameter, optional, instructs the function to return values that occur at this specified number(s) of times and can be any natural number (i.e. 1 or greater) or omitted to imply 1; multiple natural numbers; and/or comparative numbers

Note that leaving this parameter omitted or setting it to 1 makes the function equivalent (and more straightforward) to UNIQUE(reference,,1) where the "exactly_once" parameter is turned on

Note that entering non-natural number(s) will cause the function to crash to an #N/A

Note that if more than one number need to be entered, they should be included in array brackets, e.g. {2,6,3}, per native syntax

Note that if comparative numbers need to be entered, they should be included in quotes, e.g. "<6" per native syntax of functions such as COUNTIF. The four possibilities are: "<N", "<=N", ">N", and ">=N"

Note that if more than one comparative number need to be entered, they should be included in array brackets, e.g. {">2","<=8","<5",">=4"}

Note that if a comparative expression implies non-natural number(s), e.g. "<1" the function will crash to an #N/A

Note that natural numbers can be mixed with comparative numbers such as: {"<=3",7,">9"} or {"6","<5",">8"}

Note that natural numbers in quotes is permitted as in the above example

Note that including any deviations from the acceptable comparative syntax as well as including any other data type such as texts, logicals, or errors will cause the function to crash to an #N/A. This robust checking mechanism is enabled through my new PLMNC module (see description below) which replaces the PLMN in the previous update
-----------------------

As there have been multiple updates with new features, in this section, I'll include all the modules again to make it easier to track them (note that I needed to add a JAR module to handle the comparative numbers which is different from the original JAR):

NTIMES
Excel Formula:
=LAMBDA(reference,[numbers],[blanks],[output_orientation],[exclude_types],[include_types],[replace_with],[if_empty],
   LET(
      r,IF(LEN(TRIM(reference))>0,reference,""),
      n,IF(IO(numbers),PLMNC(1),PLMNC(numbers)),
      b,PLSL(blanks),
      o,PLSL(output_orientation),
      x,XTYPE(reference,3),
      j,JAS(r,x,b),
      v,IF(
         ISERROR(MATCH(
            INDEX(j,2),
            JAR(n,MAX(INDEX(j,2))),
            0
         )),
         FALSE,
         TRUE
      ),
      k,FILTER(INDEX(j,1),v),
      l,JAI(
         SWITCH(JAL(exclude_types,include_types,replace_with),
            0,k,
            1,JAC(
               exclude_types,
               include_types,
               replace_with,
               k,
               FILTER(INDEX(j,3),v)
            )
         ),
         if_empty
      ),
      IF(JAO(n),NA(),IF(o,TRANSPOSE(l),l))
   )
)

JAS (core for NTIMES)
Excel Formula:
=LAMBDA(reference,types,blanks,
   LET(
      r,JBA(reference),
      c,SEQUENCE(,ROWS(r)*COLUMNS(r)),
      i,TOROW(r),
      z,TOROW(types),
      t,{31,32,33,34},
      k,JAI(UNIQUE(FILTER(i,ISERROR(MATCH(z,t,0))),1),0),
      p,IFERROR(MATCH(IFERROR(k,ERROR.TYPE(k)),IFERROR(i,ERROR.TYPE(i)),0),0),
      a,IF(
         blanks,
         HSTACK(
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{31},0)))),1),0),
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{32},0)))),1),0),
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{33},0)))),1),0),
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{34},0)))),1),0)
         ),
         IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,t,0)))),1),0)
      ),
      y,HSTACK(k,a),
      u,HSTACK(
         p,
         LET(
            x,IFERROR(MATCH(t,z,0),0),
            IF(
               blanks,
               x,
               IFERROR(MIN(FILTER(x,x>0)),0)
            )
         )
      ),
      q,MATCH(u,c,0),
      w,LET(
         x,INDEX(z,1,q),
         IF(
            blanks,
            x,
            IF(ISERROR(MATCH(x,t,0)),x,3)
         )
      ),
      b,CHOOSEROWS(
         SORT(
            CHOOSECOLS(
               VSTACK(y,u,w),
               FILTER(SEQUENCE(,COLUMNS(u)),u>0)
            ),
            2,
            1,
            1
         ),
         {1,3}
      ),
      d,INDEX(b,1),
      g,INDEX(b,2),
      e,TOROW(IF(
         ISERROR(r),
         MATCH(ERROR.TYPE(r),ERROR.TYPE(d),0),
         IF(
            blanks,
            IF(LEN(r)=0,MATCH(types,g,0),MATCH(r,d,0)),
            MATCH(r,d,0)
         )
      )),
      f,SEQUENCE(MAX(e)),
      h,CHOOSEROWS(FREQUENCY(e,f),f),
      VSTACK(d,TRANSPOSE(h),g)
   )
)

JAR (generates a list of comparative numbers for NTIMES)
Excel Formula:
=LAMBDA(comparative_array,max_count,
   LET(
      a,comparative_array,
      d,INDEX(a,1),
      e,INDEX(a,2),
      b,MAX(max_count,e)+1,
      h,MAKEARRAY(
         b,
         COLUMNS(a),
         LAMBDA(r,c,
            LET(
               f,INDEX(d,c),
               g,INDEX(e,c),
               IF(
                  f="<",
                  IF(r<g,g-r,""),
                  IF(
                     f="<=",
                     IF(r<=g,g-r+1,""),
                     IF(
                        f=">",
                        IF(r<=b-g,r+g,""),
                        IF(
                           f=">=",
                           IF(r<=b-g+1,r+g-1,""),
                           IF(
                              f="=",
                              IF(r=1,g,""),
                              ""
                           )
                        )
                     )
                  )
               )
            )
         )
      ),
      i,TOROW(h,1),
      UNIQUE(FILTER(i,ISNUMBER(i)),1)
   )
)

XERROR.TYPE (posted separately)

XTYPE (posted separately)

PLMNC (stands for parameter limit, multiple natural comparative)
(Returns a double-row array of natural numbers and their comparative signs if the entered elements are natural numbers, the overall numbers and their comparative signs imply natural numbers, and are expressed in proper syntax; and an #N/A otherwise)
(causes the main function to crash to an #N/A if the wrong numbers, data types, or syntax is entered)
Excel Formula:
=LAMBDA(parameter,
   LET(
      p,parameter,
      a,LEFT(parameter,2),
      b,LEN(parameter),
      c,MID(parameter,3,b-2),
      d,MID(parameter,2,b-1),
      f,ISNUMBER(VALUE(parameter)),
      e,IF(f,parameter,d),
      g,VALUE(IF(a="<=",c,IF(a=">=",c,e))),
      h,ISNUMBER(g),
      i,VSTACK(
         FILTER(
            IF(
               f,
               "=",
               LEFT(
                  parameter,
                  IF(a="<=",2,IF(a=">=",2,1))
               )
            ),
            h
         ),
         g
      ),
      j,INDEX(i,1),
      k,INDEX(i,2),
      IF(
         OR(
            JAO(j),
            k<1,
            MOD(k,1),
            IF(j="<",IF(k=1,1))
         ),
         NA(),
         i
      )
   )
)

PLS (stands for "parameter limit, single")
(Returns the parameter if it is a single entry (not blank or error) and #N/A otherwise)
(Causes the function to crash to a single #N/A if the incorrect parameter is entered [either the wrong type or more than a single entry in array brackets "{}"])
Excel Formula:
=LAMBDA(parameter,
   INDEX(
      IF(
         OR(JAN(parameter),JAO(parameter),JAP(parameter)),
         NA(),
         parameter
      ),
      1
   )
)

PLSL (stands for "parameter limit, single logical")
(Returns 1 if the parameter is a single TRUE entry; 0 if the parameter is a single FALSE entry or is omitted; and #N/A otherwise)
(Causes the function to crash to a single #N/A if incorrect parameters are entered [either anything not logically evaluable or more than a single entry in array brackets "{}"]))
Excel Formula:
=LAMBDA([parameter],
   IF(
      IO(parameter),
      0,
      IF(
         JAN(parameter),
         NA(),
         LET(
            p,INDEX(parameter,1),
            IF(
               ISERROR(p),
               NA(),
               T1F0(p)
            )
         )
      )
   )
)

JAB (returns a number greater than or equal to 1 (i.e. TRUE) if the reference has the specified data type(s) and 0 (i.e. FALSE) otherwise)
Excel Formula:
=LAMBDA(types,advanced_types_array,
   IF(
      SUM(T1F0(ISERROR(MATCH(types,AllTypes,0)))),
      NA(),
      LET(
         basic_types_array,SWITCH(advanced_types_array,1,1,2,2,31,3,32,3,33,3,34,3,41,4,42,4,"","",16),
         MAP(
            advanced_types_array,
            LAMBDA(a,OR(a=types))
         )+
         MAP(
            basic_types_array,
            LAMBDA(a,OR(a=types))
         )
      )
   )
)

JAC (module for 1D (FILTER-based) "exclude_types/include_types/replace_with" with auto-shrink)
Excel Formula:
=LAMBDA(exclude_types,include_types,replace_with,main_array,advanced_types_array,
   LET(
      d,IF(IO(include_types),exclude_types,include_types),
      x,JAB(d,advanced_types_array),
      IF(
         IO(replace_with),
         FILTER(
            main_array,
            IF(IO(include_types),NOT(x),x)
         ),
         IF(
            IO(include_types),
            IF(x,replace_with,main_array),
            IF(x,main_array,replace_with)
         )
      )
   )
)

JAI (module for "if_empty")
Excel Formula:
=LAMBDA(operation,if_empty,
   IF(
      JAN(if_empty),
      NA(),
      LET(
         e,IF(
            ISERROR(operation),
            IF(ERROR.TYPE(operation)=14,1,0),
            0
         ),
         f,IF(
            ISERROR(ROWS(operation)*COLUMNS(operation)),
            1,
            0
         ),
         IF(
            e+f=2,
            IF(IO(if_empty),operation,if_empty),
            operation
         )
      )
   )
)

JAL (switch for "include_types/exclude_types")
Excel Formula:
=LAMBDA(exclude_types,include_types,replace_with,
   IF(
      JAN(replace_with),
      NA(),
      IFS(
         AND(IO(exclude_types),IO(include_types),IO(replace_with)),0,
         OR(AND(IO(include_types),NIO(exclude_types)),AND(NIO(include_types),IO(exclude_types))),1
      )
   )
)

JAN (Returns TRUE if the reference is an array (i.e. is not a single element or is not omitted) and FALSE otherwise [simplified form of ISARRAY])
Excel Formula:
=LAMBDA([reference],
   LET(
      r,IFERROR(IF(reference="","",reference),""),
      IF(
         IO(reference),
         FALSE,
         IF(ROWS(r)*COLUMNS(r)>1,TRUE,FALSE)
      )
   )
)

JAO (Returns TRUE if the reference contains at least one error and FALSE otherwise [simplified form of ISERRORS])
Excel Formula:
=LAMBDA(reference,
   IF(
      IO(reference),
      FALSE,
      IF(SUM(IF(ISERROR(reference),1,0)),TRUE,FALSE)
   )
)

JAP (Returns TRUE if the reference contains at least one blank and FALSE otherwise [simplified form of ISBLANKS])
Excel Formula:
=LAMBDA(reference,
   IF(
      IO(reference),
      NA(),
      IF(SUM(IF(IFERROR(reference,0)="",1,0)),TRUE,FALSE)
   )
)

JBA (inserts single values into array brackets "{}")
Excel Formula:
=LAMBDA(reference[if_omitted],
   IF(
      IO(reference),
      if_omitted,
      LET(
         r,reference,
         IF(
            AND(COLUMNS(IFERROR(r,""))=1,ISERROR(r)),
            CHOOSECOLS(CHOOSE({1,2},r,r),1),
            FILTER(r,SEQUENCE(,COLUMNS(r)))
         )
      )
   )
)

AllTypes
Excel Formula:
={1,2,3,4,16,31,32,33,34,41,42,161,162,163,164,165,166,167,168,169,1610,1611,1612,1613,1614,1619}

IO (shortened form of ISOMITTED)
Excel Formula:
=LAMBDA(parameter,
   ISOMITTED(parameter)
)

NIO [shortened form of NOT(ISOMITTED)]
Excel Formula:
=LAMBDA(parameter,
   NOT(ISOMITTED(parameter))
)

PO0 (Returns 0 if the parameter is omitted and the parameter itself otherwise)
Excel Formula:
=LAMBDA([parameter],
   IF(IO(parameter),0,parameter)
)

T1F0 (Returns 1 if the reference is TRUE, 0 if the reference is FALSE, and #N/A otherwise)
Excel Formula:
=LAMBDA(expression,
   IF(
      ISNUMBER(expression)+ISLOGICAL(expression),
      IF(expression,1,0),
      NA()
   )
)
 
Updated code:
1) adds support for the "not equal" operator, i.e. "<>" within the "numbers" parameter. With this update, all comparative operators can be used now.
2) optimizes code

JAS (core for NTIMES)
Excel Formula:
=LAMBDA(reference,types,blanks,
   LET(
      r,JBA(reference),
      c,SEQUENCE(,ROWS(r)*COLUMNS(r)),
      i,TOROW(r),
      z,TOROW(types),
      t,{31,32,33,34},
      k,JAI(UNIQUE(FILTER(i,ISERROR(MATCH(z,t,0))),1),0),
      p,IFERROR(MATCH(k,i,0),0)+IFERROR(MATCH(ERROR.TYPE(k),ERROR.TYPE(i),0),0),
      a,IF(
         blanks,
         HSTACK(
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{31},0)))),1),0),
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{32},0)))),1),0),
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{33},0)))),1),0),
            IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,{34},0)))),1),0)
         ),
         IFERROR(UNIQUE(FILTER(i,NOT(ISERROR(MATCH(z,t,0)))),1),0)
      ),
      y,HSTACK(k,a),
      u,HSTACK(
         p,
         LET(
            x,IFERROR(MATCH(t,z,0),0),
            IF(
               blanks,
               x,
               IFERROR(MIN(FILTER(x,x>0)),0)
            )
         )
      ),
      q,MATCH(u,c,0),
      w,LET(
         x,INDEX(z,1,q),
         IF(
            blanks,
            x,
            IF(ISERROR(MATCH(x,t,0)),x,3)
         )
      ),
      b,CHOOSEROWS(
         SORT(
            CHOOSECOLS(
               VSTACK(y,u,w),
               FILTER(SEQUENCE(,COLUMNS(u)),u>0)
            ),
            2,
            1,
            1
         ),
         {1,3}
      ),
      d,INDEX(b,1),
      g,INDEX(b,2),
      e,TOROW(IF(
         ISERROR(r),
         MATCH(ERROR.TYPE(r),ERROR.TYPE(d),0),
         IF(
            blanks,
            IF(LEN(r)=0,MATCH(types,g,0),MATCH(r,d,0)),
            MATCH(r,d,0)
         )
      )),
      f,SEQUENCE(MAX(e)),
      h,CHOOSEROWS(FREQUENCY(e,f),f),
      VSTACK(d,TRANSPOSE(h),g)
   )
)

JAR (generates a list of comparative numbers for NTIMES)
Excel Formula:
=LAMBDA(comparative_array,max_count,
   LET(
      a,comparative_array,
      d,INDEX(a,1),
      e,INDEX(a,2),
      b,MAX(max_count,e)+1,
      h,MAKEARRAY(
         b,
         COLUMNS(a),
         LAMBDA(r,c,
            LET(
               f,INDEX(d,c),
               g,INDEX(e,c),
               IF(
                  f="<",
                  IF(r<g,g-r,""),
                  IF(
                     f="<=",
                     IF(r<=g,g-r+1,""),
                     IF(
                        f=">",
                        IF(r<=b-g,r+g,""),
                        IF(
                           f=">=",
                           IF(r<=b-g+1,r+g-1,""),
                           IF(
                              f="=",
                              IF(r=1,g,""),
                              IF(
                                 f="<>",
                                 IF(AND(r<=b,r<>g),r,""),
                                 ""
                              )
                           )
                        )
                     )
                  )
               )
            )
         )
      ),
      i,TOROW(h,1),
      UNIQUE(FILTER(i,ISNUMBER(i)),1)
   )
)

PLMNC (stands for parameter limit, multiple natural comparative)
(Returns a double-row array of natural numbers and their comparative signs if the entered elements are natural numbers, the overall numbers and their comparative signs imply natural numbers, and are expressed in proper syntax; and an #N/A otherwise)
(causes the main function to crash to an #N/A if the wrong numbers, data types, or syntax is entered)
Excel Formula:
=LAMBDA(parameter,
   LET(
      p,parameter,
      a,LEFT(p,2),
      b,LEN(p),
      c,MID(p,3,b-2),
      d,MID(p,2,b-1),
      f,ISNUMBER(VALUE(p)),
      e,IF(f,p,d),
      g,VALUE(IF(a="<=",c,IF(a=">=",c,IF(a="<>",c,e)))),
      h,ISNUMBER(g),
      i,VSTACK(
         FILTER(
            IF(
               f,
               "=",
               LEFT(
                  p,
                  IF(a="<=",2,IF(a=">=",2,IF(a="<>",2,1)))
               )
            ),
            h
         ),
         g
      ),
      j,INDEX(i,1),
      k,INDEX(i,2),
      IF(
         OR(
            JAO(j),
            k<1,
            MOD(k,1),
            IF(j="<",IF(k=1,1))
         ),
         NA(),
         i
      )
   )
)
 

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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