Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Creating a long table with individual days from a day range

Hi all,

My experience with loads is limited to joins and renaming columns etc, so I need a little help!

I have a table that is arranged like this:

ID'sDay RangeValue
ID1-6*120
ID11*725
ID17*1423
ID2-10*134
ID21*436
ID25*1035
ID3-10*133
ID31*732
ID38*1430
ID315*2135

What I want to do is create a table like this (showing only ID1):

IDDayValue
ID1-620
ID1-520
ID1-420
ID1-320
ID1-220
ID1-120
ID1125
ID1225
ID1325
ID1425
ID1525
ID1625
ID1723
ID1823
ID1923
ID11023
ID11123
ID11223
ID11323
ID11423

Any ideas? Thanks

Mark

1 Reply
flipside
Partner - Specialist II
Partner - Specialist II

Hi Mark,

You could try this approach which basically finds the extremities of the Day Range and loops through to compare against the data.

//Test data

Data:
load

*,

subfield([Day Range],'*',1) as d_start,
subfield([Day Range],'*',-1) as d_end
inline [
ID, Day Range, Value
ID1, -6*1, 20
ID1, 1*7, 25
ID1, 7*14, 23
ID2, -10*1, 34
ID2, 1*4, 36
ID2, 5*10, 35
ID3, -10*1, 33
ID3, 1*7, 32
ID3, 8*14, 30
ID3, 15*21, 35]
;

//identify range extremities

Range1:
Load

min(d_start) as r_start,
max(d_end) as r_end
resident Data;

//loop through Range1
for i= peek('r_start') to peek('r_end')

NewData:

LOAD ID as n_ID, '$(i)' as n_Day, Value as n_Value

Resident Data

where d_start <= $(i) and d_end >= $(i);

next i;

I'm not sure what logic you are using when there are 2 possible values on a single day (ID1 has -6*1 and 1*7), so you may need to add code to allow for this.

flipside