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

Take the first and the last value of different fields in a single line.

Good morning/night Folks.

I'm in trouble. Now, I have something like that moviment table.

Pacientseq_movUnitbedmoved inmoved outprevious UnitPrev Moved Inprev Moved Out
00001

1

Surgery CenterSC0501/05/2017 14:05:0001/05/2017 16:00:25Clinical Center01/05/2017 13:15:0001/05/2017 14:05:00
000012UTIUTI0201/05/2017 16:00:2508/05/2017 12:00:25Surgery Center01/05/2017 14:05:0001/05/2017 16:00:25
000013UTIUTI0708/05/2017 12:00:2515/05/2017 03:50:00UTI01/05/2017 16:00:2508/05/2017 12:00:25
000014UTIUTI0715/05/2017 03:50:0017/05/2017 22:25:00UTI08/05/2017 12:00:2515/05/2017 03:50:00
000015RecoveryREC0117/05/2017 22:25:0018/05/2017 09:00:08UTI15/05/2017 03:50:0017/05/2017 22:25:00
000016HemodynamicHEM0218/05/2017 09:00:0818/05/2017 09:40:00Recovery17/05/2017 22:25:0018/05/2017 09:00:08
000017UTIUTI0118/05/2017 09:40:0021/05/2017 05:13:00Hemodynamic18/05/2017 09:00:0818/05/2017 09:40:00
000018UTIUTI0421/05/2017 05:13:0027/05/2017 16:05:10UTI18/05/2017 09:40:0021/05/2017 05:13:00
000019RecoveryREC0527/05/2017 16:05:1028/05/2017 00:00:00UTI21/05/2017 05:13:0027/05/2017 16:05:10
0000210HemodynamicHEM2502/05/2017 23:45:0003/05/2017 00:16:49Primary Care02/05/2017 22:25:0002/05/2017 23:45:00
0000211............................

  • I need to have the entry moment of each pacient at the unit, and when he left that unit but in a single line.
  • If a pacient enter the unit twice, it need to show him twice too.

So, if I filter the unit "UTI"  it gonna show something like this

pacientUnitMoved InMoved out
00001UTI01/05/2017 16:00:2517/05/2017 22:25:00
00001UTI18/05/2017 09:40:0027/05/2017 16:05:10

Anyone Have an Idea?

2 Replies
sunny_talwar

Something like this

Capture.PNG

Where Flag is created in the script like this

Table:

LOAD * INLINE [

    Pacient, seq_mov, Unit, bed, moved in, moved out, previous Unit, Prev Moved In, prev Moved Out

    00001, 1, Surgery Center, SC05, 01/05/2017 14:05:00, 01/05/2017 16:00:25, Clinical Center, 01/05/2017 13:15:00, 01/05/2017 14:05:00

    00001, 2, UTI, UTI02, 01/05/2017 16:00:25, 08/05/2017 12:00:25, Surgery Center, 01/05/2017 14:05:00, 01/05/2017 16:00:25

    00001, 3, UTI, UTI07, 08/05/2017 12:00:25, 15/05/2017 03:50:00, UTI, 01/05/2017 16:00:25, 08/05/2017 12:00:25

    00001, 4, UTI, UTI07, 15/05/2017 03:50:00, 17/05/2017 22:25:00, UTI, 08/05/2017 12:00:25, 15/05/2017 03:50:00

    00001, 5, Recovery, REC01, 17/05/2017 22:25:00, 18/05/2017 09:00:08, UTI, 15/05/2017 03:50:00, 17/05/2017 22:25:00

    00001, 6, Hemodynamic, HEM02, 18/05/2017 09:00:08, 18/05/2017 09:40:00, Recovery, 17/05/2017 22:25:00, 18/05/2017 09:00:08

    00001, 7, UTI, UTI01, 18/05/2017 09:40:00, 21/05/2017 05:13:00, Hemodynamic, 18/05/2017 09:00:08, 18/05/2017 09:40:00

    00001, 8, UTI, UTI04, 21/05/2017 05:13:00, 27/05/2017 16:05:10, UTI, 18/05/2017 09:40:00, 21/05/2017 05:13:00

    00001, 9, Recovery, REC05, 27/05/2017 16:05:10, 28/05/2017 00:00:00, UTI, 21/05/2017 05:13:00, 27/05/2017 16:05:10

    00002, 10, Hemodynamic, HEM25, 02/05/2017 23:45:00, 03/05/2017 00:16:49, Primary Care, 02/05/2017 22:25:00, 02/05/2017 23:45:00

];

FinalTable:

LOAD *,

If(Unit = Previous(Unit), Alt(Peek('Flag'), 1), RangeSum(Peek('Flag'), 1)) as Flag

Resident Table

Order By seq_mov;

DROP Table Table;

marcus_malinow
Partner - Specialist III
Partner - Specialist III

Something like this:

_PatientData:

LOAD * INLINE [

Pacient, seq_mov, Unit, bed, moved in, moved out, previous Unit, Prev Moved In, prev Moved Out

00001, 1, Surgery Center, SC05, 01/05/2017 14:05:00, 01/05/2017 16:00:25, Clinical Center, 01/05/2017 13:15:00, 01/05/2017 14:05:00

00001, 2, UTI, UTI02, 01/05/2017 16:00:25, 08/05/2017 12:00:25, Surgery Center, 01/05/2017 14:05:00, 01/05/2017 16:00:25

00001, 3, UTI, UTI07, 08/05/2017 12:00:25, 15/05/2017 03:50:00, UTI, 01/05/2017 16:00:25, 08/05/2017 12:00:25

00001, 4, UTI, UTI07, 15/05/2017 03:50:00, 17/05/2017 22:25:00, UTI, 08/05/2017 12:00:25, 15/05/2017 03:50:00

00001, 5, Recovery, REC01, 17/05/2017 22:25:00, 18/05/2017 09:00:08, UTI, 15/05/2017 03:50:00, 17/05/2017 22:25:00

00001, 6, Hemodynamic, HEM02, 18/05/2017 09:00:08, 18/05/2017 09:40:00, Recovery, 17/05/2017 22:25:00, 18/05/2017 09:00:08

00001, 7, UTI, UTI01, 18/05/2017 09:40:00, 21/05/2017 05:13:00, Hemodynamic, 18/05/2017 09:00:08, 18/05/2017 09:40:00

00001, 8, UTI, UTI04, 21/05/2017 05:13:00, 27/05/2017 16:05:10, UTI, 18/05/2017 09:40:00, 21/05/2017 05:13:00

00001, 9, Recovery, REC05, 27/05/2017 16:05:10, 28/05/2017 00:00:00, UTI, 21/05/2017 05:13:00, 27/05/2017 16:05:10

00002, 10, Hemodynamic, HEM25, 02/05/2017 23:45:00, 03/05/2017 00:16:49, Primary Care, 02/05/2017 22:25:00, 02/05/2017 23:45:00

];

PatientData:

NOCONCATENATE

LOAD

    Pacient,

    Unit,

    min([moved in]) as [moved in],

    max([moved out]) as [moved out],

    PatientUnitCounter

GROUP BY     Pacient, Unit, PatientUnitCounter

;

LOAD

    Pacient,

    seq_mov,

    Unit,

    [moved in],

    [moved out],

    if(isnull(peek('Pacient', -1)), //first record

        1,

        if(Pacient=peek('Pacient', -1) //same pacient as previous row

            and Unit=peek('Unit', -1), //same unit as previous row

            peek('PatientUnitCounter', -1),

            peek('PatientUnitCounter', -1) + 1

            )

        ) as PatientUnitCounter

RESIDENT _PatientData

ORDER BY Pacient, [moved in]

;

DROP TABLE _PatientData