# Trying to make COUNTIFS, UNIQUE, and INDIRECT play nicely together



## oenleunc (Dec 29, 2022)

Howdy,

I'm trying to (ultimately) create a visualization in Spotfire using a range full of dates (AF2:MX100), which Spotfire doesn't care for.  That's fine, I just need to count the number of unique dates per row for given two-week period.  That period would be the dates specified in E1:AE1 (26 columns denoting every other week).

Luckily I'm using Excel 365 so I can use the UNIQUE function (holy smokes does that make it easier).  However, Excel is not appreciating my formula, and after an embarrassingly long time searching for something to help, I'm finally asking for help.


```
=COUNTIFS(UNIQUE(AF2:MX2,FALSE,FALSE))<INDIRECT(F1), (UNIQUE(AF2:MX2,FALSE,FALSE))>=INDIRECT(E1)
```

Where AF2:MX2 is the range of dates I'd like to count distinct values for, and I'd like the distinct values to be between dates E1 and F1.


----------



## Dave Patton (Dec 29, 2022)

It would help if you posted an example with the forum's tool named XL2BB, Please also show the expected result.

I had one quick thought.  


Unique.xlsmABCDEF11-Dec-2231-Dec-22215-Nov-2212-Dec-2212-Dec-2215-Dec-2215-Dec-2230-Dec-223438dCell FormulasRangeFormulaB4B4=LET(x,UNIQUE(A2:F2,1,0),SUM((x>E1)*(x<F1)))


----------



## oenleunc (Dec 29, 2022)

Yup that works.  I've never seen the "let" function before.  I would love a quick explanation of the formula if you're willing.

I can't download XL2BB because work computer 

Thank you!!


----------



## Dave Patton (Dec 29, 2022)

I would love a quick explanation of the formula if you're willing.

try Excel's help for the Let function.
There are lots of good examples on this forum.

You can also try Excel Formulas  Formula Evaluate


----------

