2 Replies Latest reply: Nov 6, 2017 5:07 PM by Glenn David RSS

    Show percentage data for specific Date Range in Qlik

    Supriya R

      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.

        • Re: Show percentage data for specific Date Range in Qlik
          Glenn David

          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)';

          • Re: Show percentage data for specific Date Range in Qlik
            Luis Madriz

            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