<?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: Bar chart : trend line based on data of previous years only in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Bar-chart-trend-line-based-on-data-of-previous-years-only/m-p/2448161#M97807</link>
    <description>&lt;P&gt;I have marked your answer as accepted solution.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 May 2024 00:23:24 GMT</pubDate>
    <dc:creator>Anil_Babu_Samineni</dc:creator>
    <dc:date>2024-05-03T00:23:24Z</dc:date>
    <item>
      <title>Bar chart : trend line based on data of previous years only</title>
      <link>https://community.qlik.com/t5/App-Development/Bar-chart-trend-line-based-on-data-of-previous-years-only/m-p/2440729#M97294</link>
      <description>&lt;P&gt;Hi everyone,&lt;BR /&gt;I have this bar chart of the number of requests per quarter year.&lt;BR /&gt;There is a clear ascending linear trend that I want to visualize with a trend line. The "naive" built-in trendline from Qlik Sense is biased by the incomplete data of the current, incomplete quarter year as shown in the figure. The reasonable thing to do is to base that trend line on the years before YearStart(Today()).&lt;BR /&gt;I guess this is a pretty common thing, but I can't figure out how to implement this. Do you have a hint?&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="c6e96fe590494dabae9b9b199ef046e0.jpg" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/163980iFE9AA47A5846D6D8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="c6e96fe590494dabae9b9b199ef046e0.jpg" alt="c6e96fe590494dabae9b9b199ef046e0.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;What I tried so far:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Checking similar topics&amp;nbsp;&lt;A href="https://community.qlik.com/t5/App-Development/Reference-line-in-Bar-Chart/m-p/2116358#M91095" target="_self"&gt;here&lt;/A&gt; and &lt;A href="https://community.qlik.com/t5/App-Development/Regression-lines-and-aggregation/m-p/1771993/highlight/true#M59758" target="_self"&gt;there&lt;/A&gt;.&lt;/LI&gt;
&lt;LI&gt;To calculate the intercept and slope of the regression line, I use Linest_B() and Linest_M().&lt;/LI&gt;
&lt;LI&gt;As X values, I use numeric value of the quarter year:&amp;nbsp;(Num#(Left([Reception YearQuarter],4))+(Num#(Mid([Reception YearQuarter],7,1))-1)/4))&lt;/LI&gt;
&lt;LI&gt;As Y values, I use Aggr(Count(RequestID), [Reception YearQuarter]) over the set of Reception Dates from previous years&amp;nbsp;{1&amp;lt;[Reception Date]={"&amp;lt;$(=Date(YearStart(Floor(Today()))))"}&amp;gt;}, or as a complete expression:&amp;nbsp;Aggr(Count({1&amp;lt;[Reception Date]={"&amp;lt;$(=Date(YearStart(Floor(Today()))))"}&amp;gt;} RequestID), [Reception YearQuarter]).&lt;/LI&gt;
&lt;LI&gt;In a table showing&amp;nbsp;Reception Year-Quarter (both text and numeric) and Count(RequestID),&amp;nbsp;I succeed in correctly calculating Linest_B(Y values, X values) and&amp;nbsp;Linest_M(...) as additional measures, but not&amp;nbsp;Linest_B(...) + Linest_M(...)*X-value&lt;/LI&gt;
&lt;LI&gt;As a reference line this does not work either.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;BR /&gt;AggregatedSampleData:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;Reception Year-Quarter, Count&lt;BR /&gt;2021-Q1, 17871&lt;BR /&gt;2021-Q2, 17515&lt;BR /&gt;2021-Q3, 16443&lt;BR /&gt;2021-Q4, 19041&lt;BR /&gt;2022-Q1, 19297&lt;BR /&gt;2022-Q2, 18020&lt;BR /&gt;2022-Q3, 16881&lt;BR /&gt;2022-Q4, 19582&lt;BR /&gt;2023-Q1, 21232&lt;BR /&gt;2023-Q2, 19139&lt;BR /&gt;2023-Q3, 18494&lt;BR /&gt;2023-Q4, 21002&lt;BR /&gt;2024-Q1, 21784&lt;BR /&gt;2024-Q2, 1790&lt;/P&gt;
&lt;P&gt;];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2024 14:54:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Bar-chart-trend-line-based-on-data-of-previous-years-only/m-p/2440729#M97294</guid>
      <dc:creator>Gaël</dc:creator>
      <dc:date>2024-04-12T14:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: Bar chart : trend line based on data of previous years only</title>
      <link>https://community.qlik.com/t5/App-Development/Bar-chart-trend-line-based-on-data-of-previous-years-only/m-p/2441168#M97322</link>
      <description>&lt;P&gt;Please share sample QVF file to test and explain the outcome.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 09:03:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Bar-chart-trend-line-based-on-data-of-previous-years-only/m-p/2441168#M97322</guid>
      <dc:creator>Anil_Babu_Samineni</dc:creator>
      <dc:date>2024-04-15T09:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: Bar chart : trend line based on data of previous years only</title>
      <link>https://community.qlik.com/t5/App-Development/Bar-chart-trend-line-based-on-data-of-previous-years-only/m-p/2443570#M97517</link>
      <description>&lt;P&gt;With my limited rights, it seems I'm not able to export a QVF file.&lt;BR /&gt;In the following test data, there's an increase of +1 request per quarter year from one year to the next (total: +4 per year), with within-year variation. The data for the current year is incomplete and results in a wrong linear trend line in the bar chart of Count(RequestID) by [Reception-YearQuarter].&lt;/P&gt;
&lt;P&gt;SampleData:&lt;BR /&gt;LOAD&lt;BR /&gt;RequestID,&lt;BR /&gt;ReceptionDate,&lt;BR /&gt;Dual(Year(ReceptionDate)&amp;amp;'-Q'&amp;amp;Num(Ceil(Num(Month(ReceptionDate))/3)),QuarterStart(ReceptionDate)) AS [Reception-YearQuarter]&lt;BR /&gt;;&lt;BR /&gt;LOAD&lt;BR /&gt;RequestID,&lt;BR /&gt;Date(Date#([Date], 'YYYY-MM-DD') ) AS ReceptionDate,&lt;BR /&gt;;&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;RequestID, Date&lt;BR /&gt;9, 2022-01-01&lt;BR /&gt;10, 2022-01-01&lt;BR /&gt;11, 2022-04-01&lt;BR /&gt;12, 2022-04-01&lt;BR /&gt;13, 2022-04-01&lt;BR /&gt;14, 2022-07-01&lt;BR /&gt;15, 2022-07-01&lt;BR /&gt;16, 2022-07-01&lt;BR /&gt;17, 2022-07-01&lt;BR /&gt;18, 2022-10-01&lt;BR /&gt;19, 2022-10-01&lt;BR /&gt;20, 2022-10-01&lt;BR /&gt;21, 2023-01-01&lt;BR /&gt;22, 2023-01-01&lt;BR /&gt;23, 2023-01-01&lt;BR /&gt;24, 2023-04-01&lt;BR /&gt;25, 2023-04-01&lt;BR /&gt;26, 2023-04-01&lt;BR /&gt;27, 2023-04-01&lt;BR /&gt;28, 2023-07-01&lt;BR /&gt;29, 2023-07-01&lt;BR /&gt;30, 2023-07-01&lt;BR /&gt;31, 2023-07-01&lt;BR /&gt;32, 2023-07-01&lt;BR /&gt;33, 2023-10-01&lt;BR /&gt;34, 2023-10-01&lt;BR /&gt;35, 2023-10-01&lt;BR /&gt;36, 2023-10-01&lt;BR /&gt;37, 2024-01-01&lt;BR /&gt;38, 2024-01-01&lt;BR /&gt;39, 2024-01-01&lt;BR /&gt;40, 2024-01-01&lt;BR /&gt;41, 2024-04-01&lt;/P&gt;
&lt;P&gt;];&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Barchart.jpg" style="width: 918px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/164468i484D06B6EDC1B8CE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Barchart.jpg" alt="Barchart.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2024 15:06:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Bar-chart-trend-line-based-on-data-of-previous-years-only/m-p/2443570#M97517</guid>
      <dc:creator>Gaël</dc:creator>
      <dc:date>2024-04-22T15:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: Bar chart : trend line based on data of previous years only</title>
      <link>https://community.qlik.com/t5/App-Development/Bar-chart-trend-line-based-on-data-of-previous-years-only/m-p/2444927#M97603</link>
      <description>&lt;P&gt;If anyone is interested: I found the following solution:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;create a copy of the measure to be displayed. &lt;BR /&gt;&lt;EM&gt;In my example: count(OrderID)&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;name the copy "current year", and limit the data accordingly.&lt;BR /&gt;&lt;EM&gt;In my example: Count({$&amp;lt;[Reception Year]={"$(=Max([Reception Year]))"}&amp;gt;} OrderID)&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;name the original "previous years", limit the data accordingly and additionally make sure that data for the current year are NULL instead of zero. This is to ensure the linear regression does not include those zero values.&lt;BR /&gt;&lt;EM&gt;In my example: if(Count({$&amp;lt;[Reception Year]={"&amp;lt;$(=Max([Reception Year]))"}&amp;gt;} OrderID)&amp;gt;0, Count({$&amp;lt;[Reception Year]={"&amp;lt;$(=Max([Reception Year]))"}&amp;gt;} OrderID), NULL)&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;add a linear trend line for "previous years". Voilà!&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Trendline.png" style="width: 686px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/164718iC06DB510270098F9/image-size/large?v=v2&amp;amp;px=999" role="button" title="Trendline.png" alt="Trendline.png" /&gt;&lt;/span&gt;&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Thu, 25 Apr 2024 14:29:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Bar-chart-trend-line-based-on-data-of-previous-years-only/m-p/2444927#M97603</guid>
      <dc:creator>Gaël</dc:creator>
      <dc:date>2024-04-25T14:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: Bar chart : trend line based on data of previous years only</title>
      <link>https://community.qlik.com/t5/App-Development/Bar-chart-trend-line-based-on-data-of-previous-years-only/m-p/2448161#M97807</link>
      <description>&lt;P&gt;I have marked your answer as accepted solution.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2024 00:23:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Bar-chart-trend-line-based-on-data-of-previous-years-only/m-p/2448161#M97807</guid>
      <dc:creator>Anil_Babu_Samineni</dc:creator>
      <dc:date>2024-05-03T00:23:24Z</dc:date>
    </item>
  </channel>
</rss>

