3 Replies Latest reply on Dec 30, 2014 2:59 PM by ben kwok

# how do i count the number of dates in a column if it is equal to a specific date?

I am working within Excel and have a table with a column with many dates. all i want to do is count the number of occurances that a specific date appears. this is trivial in excel. I could do something like: =COUNTIF(startrange:endrange,"1/1/12") and it would yield the value for me. when i do this same thing in tableau:

count(

if ([xyzMonth]) = date(1/1/2012)

then [xyzMonth] end

)

it get no results. I've tried the reverse where I start with the IF statement and then count. my source data clearly has many dates equal to 1/1/2012. eventually i want to expand this to replacing the date with a parameter.

• ###### 1. Re: how do i count the number of dates in a column if it is equal to a specific date?

There's a few ways to do it. Without a calculated field, drag the Number of Records metric into the report and filter on your date.

Your calculated field logic looks correct, but try wrapping your 1/1/2012 in quotes. I.e. date("1/1/2012")

1 of 1 people found this helpful
• ###### 2. Re: how do i count the number of dates in a column if it is equal to a specific date?

Date constants are enclosed by #. No need to wrap them with the DATE function.

```IF [Order Date] = #1/1/2012# THEN [Order Date] END

```
• ###### 3. Re: how do i count the number of dates in a column if it is equal to a specific date?

ok. @kettan and @tom w solutions both worked.

in fact, using (#1/1/12#) also worked.

reversing the syntax did not work:

if ([xyzMonth]) = date("1/1/2012")

then count[xyzMonth] end

kettan's solution was slightly different where you simply created a new dimension that was a subset of the original "Order date" field and then changed the measure to count. interesting.@

1 of 1 people found this helpful