Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
berryandcherry6
Creator II
Creator II

Show percentage data for specific Date Range in Qlik

Hi ,

I have a script where i am calculating percentage, for certain date Range, say for past 21 days. Here is my script used

let varLast21Days  = Timestamp(Today() - 21,'YYYY-MM-DD hh:mm:ss');

let varToday  = Timestamp(Today(),'YYYY-MM-DD hh:mm:ss');

Load batch_id,

campaign_id,

open,

clicks,

date_created,

date_modified

from MetricsTable where date_created = '$(varToday)' or date_modified >= '$(varLast21Days)';

AGGREGATIONTABLE:

LOAD

sum(open) as sum_opens,

sum(click) as sum_Clicks,

campaign_id,

batch_id,

date_created,

date_modified resident MetricsTable  group by date_modified ,campaign_id,batch_id;

PERCENTAGETABLE:

Load

campaign_id,

batch_id,

date_modified ,

(sum_opens/sum_Clicks) as 'OPEN RATE',

Resident AGGREGATIONTABLE; 

but this script is not giving proper percentage 'OPEN RATE' for certain date range.

I want to show this percentage in Bar graph, how could i do this? Please help me on this.

3 Replies
theglenndavid
Partner - Contributor III
Partner - Contributor III

I would suggest you do the following:

1. Today() function can give you a different result from what you expect. Review the help article regarding the different timer modes available for the today() function and use the one that is most appropriate for your case.

2. Since you  are comparing dates and not factoring in time component, your variables can be defined as:

let varLast21Days  = Num((Today(1) - 21)) // set the timer mode to give the date on the date of the function call

let varToday  = Today(1);


3. Finally make sure your date fields don't have time component so your where clause should be:


from MetricsTable where Date(Floor(date_created)) = '$(varToday)' or Date(Floor(date_modified)) >= '$(varLast21Days)';

luismadriz
Specialist
Specialist

Hi Supriya,

I haven't reviewed what you've done in full but just noticed your aggregations may not be correct; when you aggregate (group) all values except the ones you're grouping by must use an aggregate function.

I hope this helps,

Luis

luismadriz
Specialist
Specialist

Hi,

Just wondering to know how you went about this one,

Cheers,

Luis

PS. When applicable please mark the appropriate replies as Correct. This will help community members know which discussions have already been addressed and have a possible known solution. Please mark replies as Helpful if the provided solution is helpful to the problem, but does not necessarily solve the indicated problem. You can mark multiple threads as Helpful if you feel additional info is useful to others