<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Average of days difference between purchases (dynamic) in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Average-of-days-difference-between-purchases-dynamic/m-p/2438971#M97138</link>
    <description>&lt;P&gt;Without an appropriate adjusted data-model you will always need aggr() constructs to perform any multi-level aggregations.&lt;/P&gt;
&lt;P&gt;I'm not sure if it would be possible respectively practically in your scenario to move the most of the logic into the data-model to get the wanted views with a single aggregation. Nevertheless you may try to calculate the date-differences with interrecord-functions, like:&lt;/P&gt;
&lt;P&gt;load *, if(Customer = previous(Customer), Date - previous(Date)) as DateOffset&lt;BR /&gt;resident Source order by Customer, Date;&lt;/P&gt;
&lt;P&gt;Depending on your real data-set and requirements you may need some more conditions and/or another sorting and it may be further useful to calculate a running counter for the customer and/or with an extra even() wrapping and/or self-joining the min/max/count of dates and similar stuff.&lt;/P&gt;</description>
    <pubDate>Mon, 08 Apr 2024 14:16:14 GMT</pubDate>
    <dc:creator>marcus_sommer</dc:creator>
    <dc:date>2024-04-08T14:16:14Z</dc:date>
    <item>
      <title>Average of days difference between purchases (dynamic)</title>
      <link>https://community.qlik.com/t5/App-Development/Average-of-days-difference-between-purchases-dynamic/m-p/2438410#M97113</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I'm trying to build something that's a bit confusing, and maybe someone could help me out.&lt;/P&gt;
&lt;P&gt;I know I can easily do this in script level, but I need to display an average of days between purchases of customers that will respond to date filters, e.g:&lt;/P&gt;
&lt;P&gt;customer 1 have bought 6 times:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;29/02/2024 - 02/01/2024 = 58 days diff&lt;/P&gt;
&lt;P&gt;27/12/2023 - 25/12/2023 = 2 days diff&lt;/P&gt;
&lt;P&gt;16/11/2023 - 12/06/2023 = 157 days diff&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in this case, the average of days would be 72,3 days, considering I'm dividing 217 / 3 (returns).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the user selects, for e.g, january, then the data should be something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;null() - 02/01/2024 = null&lt;/P&gt;
&lt;P&gt;27/12/2023 - 25/12/2023 = 2&lt;/P&gt;
&lt;P&gt;16/11/2023 - 12/06/2023 = 157&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this scenario, the avg would be 79,5 days, given I'm not considering it's purchase on 29/02/2024 because of the filter selection&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know aggr() will build a "temporary" table for calculation, maybe I could achieve this using sort, aggr, max, min, idk...?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is appreciate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2024 14:44:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Average-of-days-difference-between-purchases-dynamic/m-p/2438410#M97113</guid>
      <dc:creator>pedrohenriqueperna</dc:creator>
      <dc:date>2024-04-05T14:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: Average of days difference between purchases (dynamic)</title>
      <link>https://community.qlik.com/t5/App-Development/Average-of-days-difference-between-purchases-dynamic/m-p/2438971#M97138</link>
      <description>&lt;P&gt;Without an appropriate adjusted data-model you will always need aggr() constructs to perform any multi-level aggregations.&lt;/P&gt;
&lt;P&gt;I'm not sure if it would be possible respectively practically in your scenario to move the most of the logic into the data-model to get the wanted views with a single aggregation. Nevertheless you may try to calculate the date-differences with interrecord-functions, like:&lt;/P&gt;
&lt;P&gt;load *, if(Customer = previous(Customer), Date - previous(Date)) as DateOffset&lt;BR /&gt;resident Source order by Customer, Date;&lt;/P&gt;
&lt;P&gt;Depending on your real data-set and requirements you may need some more conditions and/or another sorting and it may be further useful to calculate a running counter for the customer and/or with an extra even() wrapping and/or self-joining the min/max/count of dates and similar stuff.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2024 14:16:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Average-of-days-difference-between-purchases-dynamic/m-p/2438971#M97138</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2024-04-08T14:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: Average of days difference between purchases (dynamic)</title>
      <link>https://community.qlik.com/t5/App-Development/Average-of-days-difference-between-purchases-dynamic/m-p/2438982#M97139</link>
      <description>&lt;P&gt;Hi, Marcus&lt;/P&gt;
&lt;P&gt;I actually gave up this idea and worked it out in the data model by adding a "days difference" field with the calculation for each sale_id, based on the last sale_id respectively. Considering each sale_id have a date/calendar field, I can actually use avg() limited to the corresponding dates applied to the filter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyways, thanks for the reply!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2024 14:44:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Average-of-days-difference-between-purchases-dynamic/m-p/2438982#M97139</guid>
      <dc:creator>pedrohenriqueperna</dc:creator>
      <dc:date>2024-04-08T14:44:28Z</dc:date>
    </item>
  </channel>
</rss>

