<?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: Script - Label field without nested if statements in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Script-Label-field-without-nested-if-statements/m-p/1784967#M61192</link>
    <description>&lt;P&gt;The class() function allows you to create buckets that have a consistent step:&lt;BR /&gt;&lt;A href="https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ConditionalFunctions/class.htm" target="_blank"&gt;https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ConditionalFunctions/class.htm&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Feb 2021 21:57:18 GMT</pubDate>
    <dc:creator>Nicole-Smith</dc:creator>
    <dc:date>2021-02-22T21:57:18Z</dc:date>
    <item>
      <title>Script - Label field without nested if statements</title>
      <link>https://community.qlik.com/t5/App-Development/Script-Label-field-without-nested-if-statements/m-p/1784900#M61186</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Working in the data load editor, I would like to label a field with informations from a Load * Inline table.&lt;/P&gt;&lt;P&gt;The trick is, I don't have a key field to apply the joint.&lt;/P&gt;&lt;P&gt;Here is the situation :&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to generate a pick up (montée en charge) chart for the Revenue Management team.&lt;/P&gt;&lt;P&gt;I have a list of booking with the following informations :&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Id&lt;/TD&gt;&lt;TD&gt;Created&lt;/TD&gt;&lt;TD&gt;Begin&lt;/TD&gt;&lt;TD&gt;End&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;01/01/2021 10:00:00&lt;/TD&gt;&lt;TD&gt;03/01/2021 12:00:00&lt;/TD&gt;&lt;TD&gt;03/01/2021 14:00:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;02/01/2021 14:00:00&lt;/TD&gt;&lt;TD&gt;16/04/2021 08:00:00&lt;/TD&gt;&lt;TD&gt;18/04/2021 18:00:00&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've generate the dates between the Created and the Begin to have a table (BookingWithDate) like that :&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Id&lt;/TD&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;LeadTime_DayNum&lt;/TD&gt;&lt;TD&gt;LeadTime_DayName_EN&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;01/01/2021&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;D-2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;02/01/2021&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;D-1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;03/01/2021&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;D-0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;02/01/2021&lt;/TD&gt;&lt;TD&gt;104&lt;/TD&gt;&lt;TD&gt;D-104&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;03/02/2021&lt;/TD&gt;&lt;TD&gt;103&lt;/TD&gt;&lt;TD&gt;D-103&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;15/04/2021&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;D-1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;16/04/2021&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;D-0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works to create a line chart with :&lt;/P&gt;&lt;P&gt;- Dimension 1 : LeadTime_DayNum&lt;/P&gt;&lt;P&gt;- Dimension 2 : date(floor(Begin),'DD/MM/YYYY')&lt;/P&gt;&lt;P&gt;- Measure : count(distinct Id)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, as we open booking up to 6 month prior, the chart has too many data in the LeadTime_DayNum to be usable, so the idea is to gather LeadTime_Num together to view them as Month.&lt;/P&gt;&lt;P&gt;I'm not keen on the ide to use nested if statement like so :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;left join (BookingWithDate)
Id,
Date,
if(LeadTime_DayNum&amp;lt;=186 and LeadTime_DayNum&amp;gt;155,dual('M-6',6)
 , if(LeadTime_DayNum&amp;lt;=155 and LeadTime_DayNum&amp;gt;124,dual('M-5',5)
  , if(LeadTime_DayNum&amp;lt;=124 and LeadTime_DayNum&amp;gt;93,dual('M-4',4)
   , if(LeadTime_DayNum&amp;lt;=93 and LeadTime_DayNum&amp;gt;62,dual('M-3',3)
    , if(LeadTime_DayNum&amp;lt;=62 and LeadTime_DayNum&amp;gt;31,dual('M-2',2)
     , if(LeadTime_DayNum&amp;lt;=31 and LeadTime_DayNum&amp;lt;0, dual('M-1',1) 
as LeadTime_Month
Resident BookingWithDate;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's not easy to read and to maintain if I wanted to add more complexity like a step every 14 days.&lt;/P&gt;&lt;P&gt;I thought of creating a Load*Inline table with the upper and lower bound and other dimensions like that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;_LOADINLINE_LeadTimeMonthInfos:
LOAD * INLINE [
MaxDay, 	MinDayExcluded, 	LeadTime_MonthNum,	LeadTime_MonthName_FR, 	LeadTime_MonthName_EN
186, 		155, 				6,							M-6,						M-6
155,		124,				5,							M-5,						M-5
124,		93,					4,							M-4,						M-4
93,			62,					3,							M-3,						M-3
62,			31,					2,							M-2,						M-2
31,			0,					1,							M-1,						M-1
];&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the idea was to do a&amp;nbsp; left join like so&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;left join (BookingWithDate)
LOAD
 LeadTime_MonthNum
Resident _LOADINLINE_LeadTimeMonthInfos
where LeadTime_DayNum &amp;lt;= MaxDay and LeadTime_DayNum&amp;gt;MinDayExcluded
;&lt;/LI-CODE&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;It obvisouly don't work as the field&amp;nbsp;LeadTime_DayNum isn't found.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A solution might be :&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Generate in a table with the 186 possibilities of LeadTime_DayNum&lt;/LI&gt;&lt;LI&gt;Do a left join a create a cartesian product&lt;/LI&gt;&lt;LI&gt;Then keep only the lines where the conditions are true (LeadTime_DayNum &amp;lt;= MaxDay and LeadTime_DayNum&amp;gt;MinDayExcluded)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;It should work but it seem unelegant and a hefty solution ... Do you have a better idea ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note : I will apply the same logic but this time with time of day but without generating all hours just the four period (Night, Morning, Afternoon, Evening).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;_LOADINLINE_SplitTimeOfDay:
LOAD * INLINE [
MinHour, 	MaxHourExcluded, 	TimeOfDayNum,	TimeOfDayName_FR, 	TimeOfDayName_EN
0, 			6, 					0,				Nuit,				Night
6,			12,					1,				Matin,				Morning
12,			18,					2,				Après-midi,			Afternoon
18,			22,					3,				Soirée,				Evening
22,			24,					0,				Nuit,				Night
];&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2021 18:54:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Script-Label-field-without-nested-if-statements/m-p/1784900#M61186</guid>
      <dc:creator>Zenpark_BI</dc:creator>
      <dc:date>2021-02-22T18:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Script - Label field without nested if statements</title>
      <link>https://community.qlik.com/t5/App-Development/Script-Label-field-without-nested-if-statements/m-p/1784967#M61192</link>
      <description>&lt;P&gt;The class() function allows you to create buckets that have a consistent step:&lt;BR /&gt;&lt;A href="https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ConditionalFunctions/class.htm" target="_blank"&gt;https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ConditionalFunctions/class.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2021 21:57:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Script-Label-field-without-nested-if-statements/m-p/1784967#M61192</guid>
      <dc:creator>Nicole-Smith</dc:creator>
      <dc:date>2021-02-22T21:57:18Z</dc:date>
    </item>
    <item>
      <title>Re: Script - Label field without nested if statements</title>
      <link>https://community.qlik.com/t5/App-Development/Script-Label-field-without-nested-if-statements/m-p/1785132#M61207</link>
      <description>&lt;P&gt;Thank for the idea !&amp;nbsp;&lt;/P&gt;&lt;P&gt;I twisted it a little to get a single digit number at the end and it worked&amp;nbsp; :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;round(SubField(class(LeadTime_DayNum,365/12),'&amp;lt;',1)/(365/12)) as LeadTime_MonthNum&lt;/LI-CODE&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;LI-CODE lang="markup"&gt;_LOADINLINE_LeadTimeMonthInfos:
LOAD * INLINE [
LeadTime_MonthNum,	LeadTime_MonthName_FR, 	LeadTime_MonthName_EN
5,					M-5,					M-5
4,					M-4,					M-4
3,					M-3,					M-3
2,					M-2,					M-2
1,					M-1,					M-1
0,					M-0,					M-0
];&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I generated the following chart&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Zenpark_BI_0-1614075211330.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/49667iA22378D01A5BED20/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Zenpark_BI_0-1614075211330.png" alt="Zenpark_BI_0-1614075211330.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, it won't work with the second part of my problem as the buckets don't have the same steps : 8 hours for the night, 6 for the morning and afternoon, and 4 for the evening ...&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 10:13:42 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Script-Label-field-without-nested-if-statements/m-p/1785132#M61207</guid>
      <dc:creator>Zenpark_BI</dc:creator>
      <dc:date>2021-02-23T10:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: Script - Label field without nested if statements</title>
      <link>https://community.qlik.com/t5/App-Development/Script-Label-field-without-nested-if-statements/m-p/1785386#M61237</link>
      <description>&lt;P&gt;Unfortunately if your buckets are different sizes, you'll need to use the nested if statements.&amp;nbsp; But I'm glad you got the class() function to work for your other piece!&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 15:14:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Script-Label-field-without-nested-if-statements/m-p/1785386#M61237</guid>
      <dc:creator>Nicole-Smith</dc:creator>
      <dc:date>2021-02-23T15:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: Script - Label field without nested if statements</title>
      <link>https://community.qlik.com/t5/App-Development/Script-Label-field-without-nested-if-statements/m-p/1786526#M61339</link>
      <description>&lt;P&gt;At least I've asked the questions, so let's go for the nested if.&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2021 10:31:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Script-Label-field-without-nested-if-statements/m-p/1786526#M61339</guid>
      <dc:creator>Zenpark_BI</dc:creator>
      <dc:date>2021-02-26T10:31:48Z</dc:date>
    </item>
  </channel>
</rss>

