Aishwarya
(Aishwarya Srinivasan)
15 June 2021 09:05
1
Hi,
I want to find the index of no of occurance of a each value (posting key) in the datatable. For example: for the below scenario
Index Posting Key
1 - 40
1 - 19
2 - 40
2 - 19
There are 4 known posting keys, so for each posting key I have to find the index from the datatable.
Please let me know how to achieve this. Thank you
CSD
(akaBot Support team)
15 June 2021 09:11
2
Hi @Aishwarya ,
Please allow us a moment to have look
Aishwarya
(Aishwarya Srinivasan)
15 June 2021 09:32
3
Sure, datatable will contain posting keys like 9,19,40,50.
This is the current method I implemented:
I assigned a variable “index” to “datatable.rows.indexof(row)”
Another variable “posting_key” to "datatable.rows(index)(“Posting Key”).tostring
This gives me
Index Posting Key
1 - 40
2 -19
3-40
4-19
Can I put a where condition in the above formula itself to get index for individual posting keys like below?
Index Posting Key
1 - 40
1 - 19
2 - 40
2 - 19
CSD
(akaBot Support team)
15 June 2021 10:05
4
We believe it should be this way:
posting_key_index = datatable.rows.indexof(row.item(“Posting Key”).ToString)
CSD
(akaBot Support team)
15 June 2021 10:32
6
Is it possible if you could send us the file? For further investigation
Aishwarya
(Aishwarya Srinivasan)
15 June 2021 11:25
7
CSD
(akaBot Support team)
15 June 2021 12:27
8
Please try to refer with this test. It is just for reference so we hope you can based on that and help you with your concern
TestIndexdata.zip (3.0 KB)
Aishwarya
(Aishwarya Srinivasan)
15 June 2021 13:24
9
I suppose you have hardcoded the index based on the row, but my requirement is based on the occurrence of the posting key. If there are 6 rows of data out of which the posting keys are like below:
Posting Key
19
40
19
50
19
50
I want to consider each posting key and give their indexes without hardcoding because it isnt in the same order everytime. Im trying to get an output based on the occurrence of posting key like below:
Index Posting Key
1 - 19
1 - 40
2 - 19
1 - 50
3 - 19
2 - 50
CSD
(akaBot Support team)
15 June 2021 14:44
11
Could you sort your datatable on posting key and loop?
for each row:
if current value == prev value, increment index, assign index
else index=1, assign index
Aishwarya
(Aishwarya Srinivasan)
15 June 2021 14:45
12
I’ll try that, thank you.
1 Like
system
(system)
Closed
30 June 2021 02:11
13
This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.