Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Aag
Contributor III
Contributor III

count of records within date range

Hello, Can someone help me what is wrong with the below calc?

I need to get distinct count of products between 2 time periods.

COUNT(distinct{<date1={">2020-11-01 <= 2020-11-20"}>}PRODUCTS)

Labels (1)
1 Solution

Accepted Solutions
MayilVahanan

Hi @Aag 

What is your date format?

COUNT(distinct{<date1={">2020-11-01 <= 2020-11-20"}>}PRODUCTS)

2020-11-01 its must be same as ur date1 format. And also, Date1 is in date format or text format? if its text format, then convert into date format via script

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

7 Replies
GaryGiles
Specialist
Specialist

Try this:

count(distinct {$<Date1={">$(=Date('2020/11/01'))<=$(=Date('2020/11/20'))"}>} PRODUCTS)

Aag
Contributor III
Contributor III
Author

Thank you @GaryGiles  I tried this.. It does not throw error, but get the result as 0 always with this condition.. 😞 

 

GaryGiles
Specialist
Specialist

I'm not sure how your dates are setup is Date1 a true date field, you might want to try it with month first:

count(distinct {$<Date1={">$(=Date('11/01/2020'))<=$(=Date('11/20/2020'))"}>} PRODUCTS)

MayilVahanan

Hi @Aag 

What is your date format?

COUNT(distinct{<date1={">2020-11-01 <= 2020-11-20"}>}PRODUCTS)

2020-11-01 its must be same as ur date1 format. And also, Date1 is in date format or text format? if its text format, then convert into date format via script

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
Aag
Contributor III
Contributor III
Author

Hi @Anonymous  Yes the date might be the issue.. but not sure what mistake I am doing.. 

In the script I gave 

Date(Date#(Salesdt,'YYYY/MM/DD')) as Salesdt, 

Option1 : In the measure I gave.. 

COUNT(distinct{<Salesdt={">2020-11-01 <=2020-11-22"}>}PRODUCT)

It still does not work.. I tried another way..

Option2:

Declared as variables..  

Let vStartDate = Date(Date#('2020-11-01','YYYY/MM/DD'));
Let vEndDate = Date(Date#('2020-11-22','YYYY/MM/DD'));

COUNT(distinct{<Salesdt={">vStartDate <=vEndDate "}>}PRODUCT)

Both options are not working.. Maybe it is still date format that I am doing incorrect.. Can you advise? 

 

Aag
Contributor III
Contributor III
Author

Appreciate if anyone has suggestions why my set analysis conditions are not working..

Aag
Contributor III
Contributor III
Author

Thanks @MayilVahanan  I figured out the issue.

Now it works. Thank you