<?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: Conditional Calculation of Prior Year Sales in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Conditional-Calculation-of-Prior-Year-Sales/m-p/1751286#M57839</link>
    <description>&lt;P&gt;You need to use the element function P() in your set analysis:&lt;/P&gt;&lt;P&gt;A basic structure to only include prior sales for customer-products in the current year:&lt;/P&gt;&lt;P&gt;sum({$&amp;lt;[Invoice Date]={"&amp;gt;=01/01/19&amp;lt;=12/31/19"},Customer=P({$&amp;lt;[Invoice Date]={"&amp;gt;=01/01/20&amp;lt;=12/31/20"}&amp;gt;} Customer),Product=P({$&amp;lt;[Invoice Date]={"&amp;gt;=01/01/20&amp;lt;=12/31/20"}&amp;gt;} Product)&amp;gt;} [Sales Amount ($)])&lt;/P&gt;&lt;P&gt;I've hard coded the dates above.&amp;nbsp; It would make it easier if you created an Invoice Year field in the load script.&amp;nbsp; You could then use a variable to switch between selected current year.&lt;/P&gt;&lt;P&gt;sum({$&amp;lt;[Invoice Year]={$(vSelectedYear)},Customer=P({$&amp;lt;[Invoice Year]={$(=$(vSelectedYear)-1)}&amp;gt;} Customer)&lt;/P&gt;&lt;P&gt;,Product=P({$&amp;lt;[Invoice Year]={$(=$(vSelectedYear)-1)}&amp;gt;} Product)&amp;gt;} [Sales Amount ($)])&lt;/P&gt;</description>
    <pubDate>Sat, 10 Oct 2020 15:51:48 GMT</pubDate>
    <dc:creator>GaryGiles</dc:creator>
    <dc:date>2020-10-10T15:51:48Z</dc:date>
    <item>
      <title>Conditional Calculation of Prior Year Sales</title>
      <link>https://community.qlik.com/t5/App-Development/Conditional-Calculation-of-Prior-Year-Sales/m-p/1751282#M57838</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;I have a sample data set where Customer, Product &amp;amp; Time period wise data is available for the last few years.&lt;/P&gt;&lt;P&gt;There is a required scenario where we need to show the reports for&lt;/P&gt;&lt;P&gt;Monthly (month-wise)&amp;nbsp;&lt;SPAN&gt;Current Year v/s Last Year Sales and&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Customer &amp;amp; Product-wise Current v/s last Year Sales.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Here we have a condition for Last Year (Prior Year) Sales Calculation i.e we should consider the Sales of Customer &amp;amp; Products for Prior Year which Customer Products having Sales in the Current Year.&lt;/P&gt;&lt;P&gt;It means if there is any Sales value available for Customer&amp;amp;Product in the Current Year, those Customer &amp;amp; Products we should only take for last year's sales calculation on a particular period. This calculation should be dynamic as we have the last 4 years of data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Dec 2021 21:08:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Conditional-Calculation-of-Prior-Year-Sales/m-p/1751282#M57838</guid>
      <dc:creator>rishikeshtiwari</dc:creator>
      <dc:date>2021-12-20T21:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Calculation of Prior Year Sales</title>
      <link>https://community.qlik.com/t5/App-Development/Conditional-Calculation-of-Prior-Year-Sales/m-p/1751286#M57839</link>
      <description>&lt;P&gt;You need to use the element function P() in your set analysis:&lt;/P&gt;&lt;P&gt;A basic structure to only include prior sales for customer-products in the current year:&lt;/P&gt;&lt;P&gt;sum({$&amp;lt;[Invoice Date]={"&amp;gt;=01/01/19&amp;lt;=12/31/19"},Customer=P({$&amp;lt;[Invoice Date]={"&amp;gt;=01/01/20&amp;lt;=12/31/20"}&amp;gt;} Customer),Product=P({$&amp;lt;[Invoice Date]={"&amp;gt;=01/01/20&amp;lt;=12/31/20"}&amp;gt;} Product)&amp;gt;} [Sales Amount ($)])&lt;/P&gt;&lt;P&gt;I've hard coded the dates above.&amp;nbsp; It would make it easier if you created an Invoice Year field in the load script.&amp;nbsp; You could then use a variable to switch between selected current year.&lt;/P&gt;&lt;P&gt;sum({$&amp;lt;[Invoice Year]={$(vSelectedYear)},Customer=P({$&amp;lt;[Invoice Year]={$(=$(vSelectedYear)-1)}&amp;gt;} Customer)&lt;/P&gt;&lt;P&gt;,Product=P({$&amp;lt;[Invoice Year]={$(=$(vSelectedYear)-1)}&amp;gt;} Product)&amp;gt;} [Sales Amount ($)])&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 15:51:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Conditional-Calculation-of-Prior-Year-Sales/m-p/1751286#M57839</guid>
      <dc:creator>GaryGiles</dc:creator>
      <dc:date>2020-10-10T15:51:48Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Calculation of Prior Year Sales</title>
      <link>https://community.qlik.com/t5/App-Development/Conditional-Calculation-of-Prior-Year-Sales/m-p/1751288#M57840</link>
      <description>&lt;P&gt;Hi Gary,&lt;/P&gt;&lt;P&gt;Thanks for the quick reply. But output does not look accurate. We should have only 31600 $ vales Sales need to show for Monthly Prior Year. Current Year (Selected Year) should always have complete data but data should be reduced for Last Year as per Customer/Product availability in the current year. We should have the below output. Please let me know if you have any conflicts.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Customer&lt;/TD&gt;&lt;TD&gt;Product&lt;/TD&gt;&lt;TD&gt;Month&lt;/TD&gt;&lt;TD&gt;2020 Sales&lt;/TD&gt;&lt;TD&gt;2019 Sales&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C1&lt;/TD&gt;&lt;TD&gt;P1&lt;/TD&gt;&lt;TD&gt;Feb&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C1&lt;/TD&g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gt;&lt;TD&gt;5900&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C2&lt;/TD&gt;&lt;TD&gt;P1&lt;/TD&gt;&lt;TD&gt;Oct&lt;/TD&gt;&lt;TD&gt;4000&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C2&lt;/TD&gt;&lt;TD&gt;P1&lt;/TD&gt;&lt;TD&gt;Nov&lt;/TD&gt;&lt;TD&gt;3000&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C2&lt;/TD&gt;&lt;TD&gt;P1&lt;/TD&gt;&lt;TD&gt;Jul&lt;/TD&gt;&lt;TD&gt;2700&lt;/TD&gt;&lt;TD&gt;3000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C3&lt;/TD&gt;&lt;TD&gt;P1&lt;/TD&gt;&lt;TD&gt;Jul&lt;/TD&gt;&lt;TD&gt;2700&lt;/TD&gt;&lt;TD&gt;3000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sat, 10 Oct 2020 15:57:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Conditional-Calculation-of-Prior-Year-Sales/m-p/1751288#M57840</guid>
      <dc:creator>rishikeshtiwari</dc:creator>
      <dc:date>2020-10-10T15:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Calculation of Prior Year Sales</title>
      <link>https://community.qlik.com/t5/App-Development/Conditional-Calculation-of-Prior-Year-Sales/m-p/1751294#M57842</link>
      <description>&lt;P&gt;Let's try a different approach.&lt;/P&gt;&lt;P&gt;Create an Invoice Month field in the load script with Month([Invoice Date]) as [Invoice Month] and use the following formula for prior year.&lt;/P&gt;&lt;P&gt;sum({$&amp;lt;[Invoice Year]={$(=$(vSelectedYear)-1)}&amp;gt;}&lt;BR /&gt;if(Match(Customer&amp;amp;Product&amp;amp;[Invoice Month],$(=Concat({$&amp;lt;[Invoice Year]={$(vSelectedYear)}&amp;gt;}distinct chr(39)&amp;amp;Customer&amp;amp;Product&amp;amp;[Invoice Month]&amp;amp;chr(39),',')))&amp;gt;0,&lt;BR /&gt;[Sales Amount ($)]))&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 20:23:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Conditional-Calculation-of-Prior-Year-Sales/m-p/1751294#M57842</guid>
      <dc:creator>GaryGiles</dc:creator>
      <dc:date>2020-10-10T20:23:54Z</dc:date>
    </item>
  </channel>
</rss>

