Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
rajender_qlik
Creator
Creator

Creating New field based on other field.

Hi Qlik Users,

I have sample data in below format.

    

Snapshot_idNo_of_pointstest_pointsnumber_of_periodssamples_per_period
141.1 1.22 1.3 1.44440
282.1 2.2 2.333 2.4 2.5 2.6 2.7 2.242
383.1 3.22 3.3 3.4 3.55555 3.6 3.77 3.88881
444.1 4.22 4.22 4.3341
545.1 5.2 5.333 5.414

and I need the output to be as below.

     

Snapshot_idDegreetest_pointsPeriodNo_of_pointsnumber_of_periodssamples_per_period
111.1Period-140
121.22Period-140
131.3Period-140
141.4444Period-140
212.1Period-1842
222.2Period-1842
232.333Period-2842
242.4Period-2842
252.5Period-3842
262.6Period-3842
272.7Period-4842
282.2Period-4842
313.1Period-1881
323.22Period-2881
333.3Period-3881
343.4Period-4881
353.55555Period-5881
363.6Period-6881
373.77Period-7881
383.888Period-8881
414.1Period-1441
424.22Period-2441
434.22Period-3441
444.33Period-4441
515.1Period-1414
525.2Period-1414
535.333Period-1414
545.4Period-1414

I have created the field Degree using Autonumber(RowNo, Snapshot_id) ,but I need script to create the field Period. How can I do it ? number_of_periods defines the periods in each snapshot_id and samples_per_period defines the number of degree's per period in each snapshot_id. Can someone help with script for creating the field Period ?

Thanks,

Raj

1 Solution

Accepted Solutions
rajender_qlik
Creator
Creator
Author

A:

LOAD Distinct Snapshot_id,

     No_of_points,

     (SubField(test_points,' ' ))  as test_points,

     number_of_periods,

     samples_per_period,

     RowNo() as RowNo

FROM

(ooxml, embedded labels, table is Sheet2);

B:

Load AutoNumber(RowNo, Snapshot_id) as Degree,

Snapshot_id,

     No_of_points,

     test_points,

     RowNo,

     number_of_periods,

     if(IsNull(samples_per_period),No_of_points,samples_per_period) as samples_per_period

    

Resident A;

DROP Table A;

C:

LOAD *,

'Period'&'-'&Ceil(Degree/samples_per_period) as Period

Resident B;

DROP Table B;

View solution in original post

7 Replies
sunny_talwar

Not entirely sure how you are creating the Period field... but rest can be done like this....

Table:

LOAD Snapshot_id,

No_of_points,

AutoNumber(RowNo(), Snapshot_id) as Degree,

SubField(test_points, ' ') as test_points,

number_of_periods,

samples_per_period;

LOAD * INLINE [

    Snapshot_id, No_of_points, test_points, number_of_periods, samples_per_period

    1, 4, 1.1 1.22 1.3 1.4444, 0

    2, 8, 2.1 2.2 2.333 2.4 2.5 2.6 2.7 2.2, 4, 2

    3, 8, 3.1 3.22 3.3 3.4 3.55555 3.6 3.77 3.888, 8, 1

    4, 4, 4.1 4.22 4.22 4.33, 4, 1

    5, 4, 5.1 5.2 5.333 5.4, 1, 4

];

rajender_qlik
Creator
Creator
Author

I need the Period field. I have achieved rest of transform in the table.

sunny_talwar

Hahahaha okay... what is the logic?

rajender_qlik
Creator
Creator
Author

Here you go.


number_of_periods defines the periods in each snapshot_id and samples_per_period defines the number of degree's per period in each snapshot_id.

sunny_talwar

Don't think I understand still... Why is everything within blue circle is all Period-1, but the other one changes?

Capture.PNG

rajender_qlik
Creator
Creator
Author

When Snapshot_id = '1', No_of_points = '4' tells total degree's as 1,2,3,4.  since Number_of_periods = '0' its considered as 1 period so all blue is period-1 for snapshot_id = '1'.

When Snapshot_id = '2' , No_of_points = '8' so the degree = 1,2,3,4,5,6,7,8. other field which shows Number_of_periods = '4' in that snapshot_id = '2'.  So the other field shows samples_per_period = '2'. So When snapshot_id ='2' you have 4 periods taking every two degrees as one period.

Similarly, each snapshot_id has total number of  degrees per period and samples per period.

rajender_qlik
Creator
Creator
Author

A:

LOAD Distinct Snapshot_id,

     No_of_points,

     (SubField(test_points,' ' ))  as test_points,

     number_of_periods,

     samples_per_period,

     RowNo() as RowNo

FROM

(ooxml, embedded labels, table is Sheet2);

B:

Load AutoNumber(RowNo, Snapshot_id) as Degree,

Snapshot_id,

     No_of_points,

     test_points,

     RowNo,

     number_of_periods,

     if(IsNull(samples_per_period),No_of_points,samples_per_period) as samples_per_period

    

Resident A;

DROP Table A;

C:

LOAD *,

'Period'&'-'&Ceil(Degree/samples_per_period) as Period

Resident B;

DROP Table B;