Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Assigning Rank in Load Script

Hi All,

I have data in this format.

DATE_IDPATIENT_IDPHY_IDValue
11126
111125
21118
211121
315114
31122
35121
37118
311122
41125
411115
41217
415114
420121

I need to assign rank in on basis of this logic. In a paticular Date Id , if a phy gets 4 patients then Patients are assigned 1,2,3,4.

something like this,

DATE_IDPATIENT_IDPHY_IDValuePatient_Rank
111261
1111252
211181
2111212
3151143
311221
351212
371183
3111224
411251
4111152
412173
4151144
4201215

Kindly let me know how to achieve this.

Thanks

Gauraw

1 Solution

Accepted Solutions
jagan
Luminary Alumni
Luminary Alumni

Sort the data by date_id and phy_id. This works.

View solution in original post

4 Replies
jagan
Luminary Alumni
Luminary Alumni

Hi Gaurav,

Please try below script

 

Test:

LOAD
*,
If(Previous(DATE_ID) <> DATE_ID OR Previous(PHY_ID) <> PHY_ID, 1, Peek('Rank') + 1) AS Rank
INLINE [
DATE_ID, PATIENT_ID, PHY_ID, Value
1, 1, 1, 26
1, 11, 1, 25
2, 1, 1, 18
2, 11, 1, 21
3, 15, 1, 14
3, 1, 1, 22
3, 5, 1, 21
3, 7, 1, 18
3, 11, 1, 22
4, 1, 1, 25
4, 11, 1, 15
4, 12, 1, 7
4, 15, 1, 14
4, 20, 1, 21
]
;

Hope this helps you.

Regards,

Jagan.

Not applicable
Author

Thanx for reply Jagan

I have data like this but the logic suggested by you is not working for below data.kindly check.

DATE_IDPATIENT_IDPHY_IDValue
11126
12218
13321
14420
15514
16619
17723
18824
19927
1101028
111125
112222
113317
114421
115517
116624
117728
118827
119920
1201021
21118
22216
23315
24425
25521
26624
27719
28824
29923
2101014
211121
212216
213317
214416
215523
216623
217718
218816
219915
2201018
31122
32220
33322
34425
35524
36617
37714
38821
39917
3101024
311122
312228
313322
314420
315526
316614
317717
318814
319923
3201019
41125
42222
43319
44425
45522
46618
47720
48826
49915
4101021
411115
412228
413318
414418
415522
416620
417720
418825
419921
4201019

Thanks

Gauraw

Not applicable
Author

Hi,

I would load first into a temp table.

After that, I would load this into a definitve table but

1) by sorting the temp table as you wish (for the rank)

2) by adding the rank field using peek() or previous() function, sth like

if (peek ('DATE_ID') <> DATE_ID, 1, peek('MyRank')+1) as MyRank

inside the if, you must test if you restart from 1 or if you add to the previous Rank.

For these functions, you can read further the helpfile.

Fabrice

jagan
Luminary Alumni
Luminary Alumni

Sort the data by date_id and phy_id. This works.