Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi there,
I have recently started using qlikview. I need some help.
As an example, there are 3 fields 'NAME' , 'SALES' and 'PERIOD':
NAME SALES PERIOD
A 100 0
A 200 1
B 100 0
B 300 1
How do I add one field in qlikview script and realize the following datatable:
NAME SALES PERIOD finalsale
A 100 0 100
A 200 1 300
B 100 0 100
B 300 1 300
As you see, when period =1, the finalsale is the sum of SALES from period = 0 and 1;
I have to sort the data in script, can anyone please tell me how to realize it.
Your assistance will be highly appreciated.
Thanks,
Loong
Hi there,
There is a mistake in the second table.
It should be
NAME SALES PERIOD finalsale
A 100 0 100
A 200 1 300
B 100 0 100
B 300 1 400
What will happen if you data is like this
NAME SALES PERIOD
A 100 0
A 200 1
A 300 0
A 400 1
B 100 0
B 300 1
What would be the output now?
Hi Stalwar,
In my situation, there will not be duplicate name.
But if so,
the outcome should be
NAME SALES PERIOD final
A 100 0 400 (which is 100 + 300 )
A 200 1 1000 (which is 100 + 200 + 300+ 400)
A 300 0 400 (which is 100 + 300 )
A 400 1 1000 (which is 100 + 200 + 300+ 400)
B 100 0 100 keep 100
B 300 1 400 (which is 100 + 300 ) from B
Or another simple example:
NAME SALES PERIOD
A 100 0
A 200 1
B 300 0
B 400 1
C 100 0
C 300 1
GO TO
NAME SALES PERIOD final
A 100 0 100
A 200 1 300(which is 100 + 200 )
B 300 0 300
B 400 1 700(which is 300+ 400)
C 100 0 100 keep 100
C 300 1 400 (which is 100 + 300 )
or we can have another simple example
NAME SALES PERIOD
A 100 0
A 200 1
B 300 0
B 400 1
C 100 0
C 300 1
GO TO
NAME SALES PERIOD final
A 100 0 100
A 200 1 300(which is 100 + 200 )
B 300 0 300
B 400 1 700(which is 300+ 400)
C 100 0 100 keep 100
C 300 1 400 (which is 100 + 300 )
@zlong1 wrote:
NAME SALES PERIOD final
A 100 0 100
A 200 1 300(which is 100 + 200 )
B 300 0 300
B 400 1 700(which is 300+ 400)
C 100 0 100 keep 100
C 300 1 400 (which is 100 + 300 )
Why is this output different from the one above
Seems like the input is the same... but 4th row for A has 1000 in one case and 700 in another?
Hi Stalwar,
The names are different in the two tables.
In my situation, there will not be a name with diverse value when period = 0.
When period = 0 . A will have only one value; when PERIOD =1 , A will have only one value too.
Therefore, I add a new name c into your table and change a little bit.
NAME SALES PERIOD final
A 100 0 100
A 200 1 300(which is 100 + 200 )
B 300 0 300
B 400 1 700(which is 300+ 400)
C 100 0 100 keep 100
C 300 1 400 (which is 100 + 300 )
D 5 0 5
D 7 1 12
E 20 0 20
E 30 1 50
......
The above table is the outcome what I want to realize.
Thanks a lot for your help.
Best,
Zlong
Try something like this
Table: LOAD * INLINE [ NAME, SALES, PERIOD A, 100, 0 A, 200, 1 B, 300, 0 B, 400, 1 C, 100, 0 C, 300, 1 D, 5, 0 D, 7, 1 E, 20, 0 E, 30, 1 ]; FinalTable: LOAD *, If(NAME = Previous(NAME), RangeSum(Peek('Final'), SALES), SALES) as Final Resident Table Order By NAME, PERIOD; DROP Table Table;