Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
mwallman
Contributor

How to generate a random date in a 150 day range before a Start Date?

Hi all,

How to generate a random date in a 150 day range before a Start Date?

I believe I can use the Rand() function but I am not sure how to set it so that from the Start Date field it can generate any date 150 before the start date.

Any help please?

3 Replies
MVP
MVP

Re: How to generate a random date in a 150 day range before a Start Date?

Maybe something like

LOAD *,

          Date(StartDate-Ceil(RAND()*150)) as RandomDate

LOAD StartDate

FROM ...;

Re: How to generate a random date in a 150 day range before a Start Date?

Something like this:

LOAD Date(Today() - Ceil(Rand() * 150)) as Date

Replace Today() with your Start Date

jyothish8807
Honored Contributor II

Re: How to generate a random date in a 150 day range before a Start Date?

Hi Michael,

Try like this:

let vStartdate= num(today());

Temp_date:

load date($(vStartdate)+rowno()-1) as New_Date

AutoGenerate 150;

or

let vStartdate= num(today());

Temp_date:

load date($(vStartdate)+Ceil(Rand() * 150)) as New_Date

AutoGenerate 150;

Regards

KC

Best Regards,
KC
Community Browser