<?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 Comparing 2 different date fields against each other with IF statement to create new dimension in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Comparing-2-different-date-fields-against-each-other-with-IF/m-p/2447482#M97757</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;I'm trying to create a dimension where I can compare two different date fields to each other and return a result from an IF statement for each month in a pivot table format.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;First Date field = Transaction Month [Transmonth]&lt;/P&gt;
&lt;P&gt;Second Date field = Report Month [Reportmnth]&lt;/P&gt;
&lt;P&gt;So I'm trying to show a pivot table with Report Month as column headings and then create a formula that compares the Transaction month to the Report month and if it is the same month then return "Current Month" , if the transaction period is the month before the Report Month return "Prior Month" and if the Transaction Period is older than 2 months return "Older".&lt;/P&gt;
&lt;P&gt;Data would like this for example&lt;/P&gt;
&lt;TABLE width="394"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="94"&gt;Report Month&lt;/TD&gt;
&lt;TD width="174"&gt;Transaction Month&lt;/TD&gt;
&lt;TD width="126"&gt;Sales&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Jan-24&lt;/TD&gt;
&lt;TD&gt;Jan-24&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Jan-24&lt;/TD&gt;
&lt;TD&gt;Jan-24&lt;/TD&gt;
&lt;TD&gt;25&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Jan-24&lt;/TD&gt;
&lt;TD&gt;Dec-24&lt;/TD&gt;
&lt;TD&gt;30&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D width="114"&gt;Jan-24&lt;/TD&gt;
&lt;TD width="77"&gt;Feb-24&lt;/TD&gt;
&lt;TD width="87"&gt;Mar-24&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Current Month&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Prior Month&lt;/TD&gt;
&lt;TD&gt;25&lt;/TD&gt;
&lt;TD&gt;15&lt;/TD&gt;
&lt;TD&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Older&lt;/TD&gt;
&lt;TD&gt;80&lt;/TD&gt;
&lt;TD&gt;45&lt;/TD&gt;
&lt;TD&gt;40&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the following formula and it works for to return current month, but then only returns "Older" for the rest and not the prior month for the data for the month before.&lt;/P&gt;
&lt;P&gt;=if([Transmonth.autoCalendar.YearMonth]=[Reportmnth.autoCalendar.YearMonth],'Current Month',&lt;BR /&gt;if([Transmonth.autoCalendar.Date]&amp;gt;MonthsEnd([Reportmnth.autoCalendar.Date],-2),'Prior Month','Older'))&lt;/P&gt;
&lt;P&gt;Any help is much appreciated&lt;/P&gt;</description>
    <pubDate>Wed, 01 May 2024 17:27:15 GMT</pubDate>
    <dc:creator>JustinM</dc:creator>
    <dc:date>2024-05-01T17:27:15Z</dc:date>
    <item>
      <title>Comparing 2 different date fields against each other with IF statement to create new dimension</title>
      <link>https://community.qlik.com/t5/App-Development/Comparing-2-different-date-fields-against-each-other-with-IF/m-p/2447482#M97757</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;I'm trying to create a dimension where I can compare two different date fields to each other and return a result from an IF statement for each month in a pivot table format.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;First Date field = Transaction Month [Transmonth]&lt;/P&gt;
&lt;P&gt;Second Date field = Report Month [Reportmnth]&lt;/P&gt;
&lt;P&gt;So I'm trying to show a pivot table with Report Month as column headings and then create a formula that compares the Transaction month to the Report month and if it is the same month then return "Current Month" , if the transaction period is the month before the Report Month return "Prior Month" and if the Transaction Period is older than 2 months return "Older".&lt;/P&gt;
&lt;P&gt;Data would like this for example&lt;/P&gt;
&lt;TABLE width="394"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="94"&gt;Report Month&lt;/TD&gt;
&lt;TD width="174"&gt;Transaction Month&lt;/TD&gt;
&lt;TD width="126"&gt;Sales&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Jan-24&lt;/TD&gt;
&lt;TD&gt;Jan-24&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Jan-24&lt;/TD&gt;
&lt;TD&gt;Jan-24&lt;/TD&gt;
&lt;TD&gt;25&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Jan-24&lt;/TD&gt;
&lt;TD&gt;Dec-24&lt;/TD&gt;
&lt;TD&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Jan-24&lt;/TD&gt;
&lt;TD&gt;Nov-24&lt;/TD&gt;
&lt;TD&gt;50&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Feb-24&lt;/TD&gt;
&lt;TD&gt;Feb-24&lt;/TD&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Feb-24&lt;/TD&gt;
&lt;TD&gt;Jan-24&lt;/TD&gt;
&lt;TD&gt;15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Feb-24&lt;/TD&gt;
&lt;TD&gt;Dec-24&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Feb-24&lt;/TD&gt;
&lt;TD&gt;Nov-24&lt;/TD&gt;
&lt;TD&gt;25&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Mar-24&lt;/TD&gt;
&lt;TD&gt;Mar-24&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Mar-24&lt;/TD&gt;
&lt;TD&gt;Feb-24&lt;/TD&gt;
&lt;TD&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Mar-24&lt;/TD&gt;
&lt;TD&gt;Jan-24&lt;/TD&gt;
&lt;TD&gt;40&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I'm trying to get it to look like this;&lt;/P&gt;
&lt;P&gt;Report Month is the column headings&lt;/P&gt;
&lt;TABLE width="377"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="99"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="114"&gt;Jan-24&lt;/TD&gt;
&lt;TD width="77"&gt;Feb-24&lt;/TD&gt;
&lt;TD width="87"&gt;Mar-24&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Current Month&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Prior Month&lt;/TD&gt;
&lt;TD&gt;25&lt;/TD&gt;
&lt;TD&gt;15&lt;/TD&gt;
&lt;TD&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Older&lt;/TD&gt;
&lt;TD&gt;80&lt;/TD&gt;
&lt;TD&gt;45&lt;/TD&gt;
&lt;TD&gt;40&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the following formula and it works for to return current month, but then only returns "Older" for the rest and not the prior month for the data for the month before.&lt;/P&gt;
&lt;P&gt;=if([Transmonth.autoCalendar.YearMonth]=[Reportmnth.autoCalendar.YearMonth],'Current Month',&lt;BR /&gt;if([Transmonth.autoCalendar.Date]&amp;gt;MonthsEnd([Reportmnth.autoCalendar.Date],-2),'Prior Month','Older'))&lt;/P&gt;
&lt;P&gt;Any help is much appreciated&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2024 17:27:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Comparing-2-different-date-fields-against-each-other-with-IF/m-p/2447482#M97757</guid>
      <dc:creator>JustinM</dc:creator>
      <dc:date>2024-05-01T17:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing 2 different date fields against each other with IF statement to create new dimension</title>
      <link>https://community.qlik.com/t5/App-Development/Comparing-2-different-date-fields-against-each-other-with-IF/m-p/2454120#M98249</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/134964"&gt;@JustinM&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I'm not sure about what &lt;SPAN&gt;Transmonth.autoCalendar.YearMonth and&amp;nbsp;Reportmnth.autoCalendar.YearMonth are in your data model, but&amp;nbsp;&lt;/SPAN&gt;you can try with something like this:&lt;/P&gt;
&lt;P&gt;=if(Date(Date#(Transmonth, 'MMM-YY')) = Date(Date#(Reportmnth, 'MMM-YY')), 'Current Month',&lt;BR /&gt;if(Date(Date#(Transmonth, 'MMM-YY')) = AddMonths(Date#(Reportmnth, 'MMM-YY'), -1), 'Prior Month',&lt;BR /&gt;if(Date(Date#(Transmonth, 'MMM-YY')) &amp;lt;= AddMonths(Date#(Reportmnth, 'MMM-YY'), -2), 'Older')))&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 09:48:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Comparing-2-different-date-fields-against-each-other-with-IF/m-p/2454120#M98249</guid>
      <dc:creator>F_B</dc:creator>
      <dc:date>2024-05-20T09:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing 2 different date fields against each other with IF statement to create new dimension</title>
      <link>https://community.qlik.com/t5/App-Development/Comparing-2-different-date-fields-against-each-other-with-IF/m-p/2454126#M98250</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/134964"&gt;@JustinM&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;dont use autocalendar and use proper calendar by writitng it in script - autocalendar is just creating mess as is rather poor practice for
&lt;OL&gt;
&lt;LI&gt;you can use in load script Date(MonthStart(Reportmnth),'MMM-YYYY') as [Report Month]&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;another good practice is to do necessary steps in load script so for that you can just create field during reload such as:
&lt;OL&gt;
&lt;LI&gt;&lt;SPAN&gt;If(MonthStart(Transmonth)=MonthStart(Reportmnth),'Current Month',&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;If(MonthStart(Transmonth)=MonthStart(Reportmnth,-1),'Prior Month','Older')) as XYZ&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Then you use XYZ and[Report Month] as diemensions in your pivot table.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;SPAN&gt;Lastly - using data manager is not a good practice for data modeling. It is much better to use load script editor where you have full control over what is happening with the data. If you are not familiar with it it would be good to start with learning data scripting in Qlik as that makes the whole UI build so much easier and simpler.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;cheers&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 10:10:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Comparing-2-different-date-fields-against-each-other-with-IF/m-p/2454126#M98250</guid>
      <dc:creator>Lech_Miszkiewicz</dc:creator>
      <dc:date>2024-05-20T10:10:30Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing 2 different date fields against each other with IF statement to create new dimension</title>
      <link>https://community.qlik.com/t5/App-Development/Comparing-2-different-date-fields-against-each-other-with-IF/m-p/2454162#M98256</link>
      <description>&lt;P&gt;Thank you for this. It helps a lot. Not yet quite giving me the result I'm looking for but has pointed me in right direction, so that I can fiddle with it and correct my scripts. Will post if I find my error.&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 11:47:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Comparing-2-different-date-fields-against-each-other-with-IF/m-p/2454162#M98256</guid>
      <dc:creator>JustinM</dc:creator>
      <dc:date>2024-05-20T11:47:33Z</dc:date>
    </item>
  </channel>
</rss>

