<?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: Target date 30 working days from date in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Target-date-30-working-days-from-date/m-p/2453560#M98191</link>
    <description>&lt;P&gt;I did look at the functions but failed to find the right one.&lt;/P&gt;</description>
    <pubDate>Fri, 17 May 2024 09:22:20 GMT</pubDate>
    <dc:creator>nickking</dc:creator>
    <dc:date>2024-05-17T09:22:20Z</dc:date>
    <item>
      <title>Target date 30 working days from date</title>
      <link>https://community.qlik.com/t5/App-Development/Target-date-30-working-days-from-date/m-p/2453287#M98160</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have several measures where I need to identify if an action happened a specified number of working days after a supplier was instructed. Just adding a fixed number of days to a date doesn't take into account the differing lengths of each month. So rather than calculating the number of networkdays between two dates I need to add 30 networkdays to a date to get the target date.&lt;/P&gt;
&lt;P&gt;Does anyone have any idea how I might achieve this?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Nick&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2024 15:50:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Target-date-30-working-days-from-date/m-p/2453287#M98160</guid>
      <dc:creator>nickking</dc:creator>
      <dc:date>2024-05-16T15:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: Target date 30 working days from date</title>
      <link>https://community.qlik.com/t5/App-Development/Target-date-30-working-days-from-date/m-p/2453447#M98182</link>
      <description>&lt;P&gt;Hi Nick,&lt;/P&gt;
&lt;P&gt;This is a fun challenge. Here is one example of how you can do it. Attached an image of the data model after this example. Adapt to your use case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;// Load holidays into a table&lt;BR /&gt;// This is an Inline table as an example. You can store elsewhere and load from there&lt;BR /&gt;// I added my birthday and towel day just for fun&lt;BR /&gt;Holidays:&lt;BR /&gt;LOAD&lt;BR /&gt;Date#(HolidayDate, 'YYYY-MM-DD') as HolidayDate&lt;BR /&gt;INLINE [&lt;BR /&gt;HolidayDate&lt;BR /&gt;2024-01-01&lt;BR /&gt;2024-05-07&lt;BR /&gt;2024-05-25 &lt;BR /&gt;2024-07-04&lt;BR /&gt;2024-11-28&lt;BR /&gt;2024-12-25&lt;BR /&gt;];&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;// Create a transactional table&lt;BR /&gt;Transactions:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;TransactionID, TransactionDate, Amount&lt;BR /&gt;1, 2024-01-02, 100&lt;BR /&gt;2, 2024-02-15, 150&lt;BR /&gt;3, 2024-03-10, 200&lt;BR /&gt;4, 2024-04-20, 250&lt;BR /&gt;5, 2024-05-30, 300&lt;BR /&gt;];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;// Generate a series of dates for each transaction&lt;BR /&gt;TempDates:&lt;BR /&gt;LOAD &lt;BR /&gt;TransactionID,&lt;BR /&gt;IterNo() AS DayIncrement,&lt;BR /&gt;Date(TransactionDate + IterNo() - 1) AS TempDate&lt;BR /&gt;RESIDENT Transactions&lt;BR /&gt;WHILE IterNo() &amp;lt;= 60; // Generate enough days to cover 30 working days&lt;/P&gt;
&lt;P&gt;// Filter out weekends and holidays&lt;BR /&gt;FilteredDates:&lt;BR /&gt;LOAD&lt;BR /&gt;TransactionID,&lt;BR /&gt;TempDate AS WorkDate&lt;BR /&gt;RESIDENT TempDates&lt;BR /&gt;WHERE Not Match(Num(WeekDay(TempDate)), 5, 6) // Weekdays only&lt;BR /&gt;AND NOT Exists(HolidayDate, TempDate); // Exclude holidays&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;// Add a row number to each workday per transaction&lt;BR /&gt;RankedWorkdays:&lt;BR /&gt;LOAD&lt;BR /&gt;TransactionID,&lt;BR /&gt;WorkDate,&lt;BR /&gt;If(Peek('TransactionID') = TransactionID, Peek('WorkdayRank') + 1, 1) AS WorkdayRank&lt;BR /&gt;RESIDENT FilteredDates&lt;BR /&gt;ORDER BY TransactionID, WorkDate;&lt;/P&gt;
&lt;P&gt;// Select the workday that is 30 days from the transaction date&lt;BR /&gt;Left Join(Transactions)&lt;BR /&gt;LOAD&lt;BR /&gt;TransactionID,&lt;BR /&gt;WorkDate AS TargetDate&lt;BR /&gt;RESIDENT RankedWorkdays&lt;BR /&gt;WHERE WorkdayRank = 30;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;// Drop temporary tables&lt;BR /&gt;DROP TABLE TempDates;&lt;BR /&gt;DROP TABLE FilteredDates;&lt;BR /&gt;DROP TABLE RankedWorkdays;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="igoralcantara_0-1715924001561.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/166278iAEFA25FCA7C329D6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="igoralcantara_0-1715924001561.png" alt="igoralcantara_0-1715924001561.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 05:33:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Target-date-30-working-days-from-date/m-p/2453447#M98182</guid>
      <dc:creator>igoralcantara</dc:creator>
      <dc:date>2024-05-17T05:33:29Z</dc:date>
    </item>
    <item>
      <title>Re: Target date 30 working days from date</title>
      <link>https://community.qlik.com/t5/App-Development/Target-date-30-working-days-from-date/m-p/2453473#M98183</link>
      <description>&lt;P&gt;Attached is a script which autogenerates mapping table. You can just adjust range of dates required and use it for mapping&lt;/P&gt;
&lt;P&gt;Cheers&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;//	Create variable with public holidays (Uncomment and update accordingly)
				
//     Holidays:
//     Load
//         Concat(Distinct Date(HolidayDate),',') as HolidayDates
//     FROM
//         [your holiday table]				
//     ;

//     Let vHolidays = Peek('HolidayDates',0,'Holidays');

//     Drop Table Holidays;

//	from 2020 to End of next year // adjust to your liking
    
        Let start_date 	= Floor(Makedate(2020,1,1));
        let end_date	= Floor(YearEnd(Today(),1));

        temp_calendar:
        Load
            Floor($(start_date) + Rowno()) as date_date
            ,Floor($(start_date) + Rowno()) as temp_date
        AutoGenerate
            ($(end_date)-$(start_date))
        ;

//	create empty table

        map_30_networkdays_temp:
        Load
            date(1) 	as from
            ,date(1) 	as to
        AutoGenerate
            0
        ;

//	Loop through dates and create mapping of from-to dates which are createing 30 networkdays combination

        For each v_date in FieldValueList('temp_date')
        Trace v_date is: $(v_date);
        
        	NoConcatenate 
            temp_map:
            Load Distinct
            	temp_date												as from_temp
            	,temp_date+Iterno()-1 									as to_temp
                ,NetWorkDays((temp_date),(temp_date+Iterno()-1))		as networkdays
            Resident
            	temp_calendar
            While
            	NetWorkDays(Date((temp_date)),Date(temp_date+Iterno()-1)) &amp;lt;=30
                and temp_date=$(v_date)
            ;
//
//NetWorkDays((temp_date),(temp_date+Iterno()-1),$(vHolidays)) // That is where $(vHolidays)needs to go	
//	Add record to mapping table

            Concatenate (map_30_networkdays_temp)
            Load
            	date(from_temp) 	as from
                ,date(to_temp)		as to
            Resident
            	temp_map
            Where
            	networkdays = 30
			;
            
            Drop Table temp_map;
            
       	Next

//	Drop table 
		
       	Drop table temp_calendar;

//	Final mapping table needs to be filtered to use first day meeting 30 networkdays requirement
//	Use this map to map your date to "min_to" date in your app (uncomment "Mapping" and applymap in your data script)
		
        //Mapping
        map_30_networkdays:
        Load
            from
            ,date(min(to)) as min_to
        Resident
            map_30_networkdays_temp
        Group by
        	from
        ;
        
        Drop table map_30_networkdays_temp;
        
exit script;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result is a mapping table with dates "from" and "min_to".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have publicholiday calendar you need to add array of public holidays to the networday function in the script.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lech_Miszkiewicz_0-1715928835940.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/166291i1C9DF6245FB6E7AB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Lech_Miszkiewicz_0-1715928835940.png" alt="Lech_Miszkiewicz_0-1715928835940.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 07:07:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Target-date-30-working-days-from-date/m-p/2453473#M98183</guid>
      <dc:creator>Lech_Miszkiewicz</dc:creator>
      <dc:date>2024-05-17T07:07:06Z</dc:date>
    </item>
    <item>
      <title>Re: Target date 30 working days from date</title>
      <link>https://community.qlik.com/t5/App-Development/Target-date-30-working-days-from-date/m-p/2453532#M98187</link>
      <description>&lt;P&gt;Hi Nick,&lt;/P&gt;
&lt;P&gt;The function lastworkdate() should do what you need:&amp;nbsp;&lt;A href="https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fhelp.qlik.com%2Fen-US%2Fsense%2FFebruary2024%2FSubsystems%2FHub%2FContent%2FSense_Hub%2FScripting%2FDateAndTimeFunctions%2Flastworkdate.htm&amp;amp;data=05%7C02%7Cemma.bucys%40uk.rsagroup.com%7Cf6a9aae60b264dac60e308dc7646d75b%7C4dc567e42b824a00bcdbf1f6782a0f6e%7C0%7C0%7C638515293905717983%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&amp;amp;sdata=R0KgmNpUMiLm3Tv4wLHg9QKdHgMHIDGO5bn9nIbUarI%3D&amp;amp;reserved=0" target="_blank"&gt;lastworkdate - script and chart function&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 08:34:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Target-date-30-working-days-from-date/m-p/2453532#M98187</guid>
      <dc:creator>em_bu</dc:creator>
      <dc:date>2024-05-17T08:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: Target date 30 working days from date</title>
      <link>https://community.qlik.com/t5/App-Development/Target-date-30-working-days-from-date/m-p/2453553#M98188</link>
      <description>&lt;P&gt;funny - I didnt even think about looking at the built in functions &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt; well done&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/299475"&gt;@em_bu&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 09:13:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Target-date-30-working-days-from-date/m-p/2453553#M98188</guid>
      <dc:creator>Lech_Miszkiewicz</dc:creator>
      <dc:date>2024-05-17T09:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: Target date 30 working days from date</title>
      <link>https://community.qlik.com/t5/App-Development/Target-date-30-working-days-from-date/m-p/2453560#M98191</link>
      <description>&lt;P&gt;I did look at the functions but failed to find the right one.&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 09:22:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Target-date-30-working-days-from-date/m-p/2453560#M98191</guid>
      <dc:creator>nickking</dc:creator>
      <dc:date>2024-05-17T09:22:20Z</dc:date>
    </item>
  </channel>
</rss>

