Index of a value in Datatable

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

image

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

Hi @Aishwarya ,
Please allow us a moment to have look

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

We believe it should be this way:
posting_key_index = datatable.rows.indexof(row.item(“Posting Key”).ToString)

I am getting this error

Is it possible if you could send us the file? For further investigation

Index.zip (5.3 KB) JV entries sample.xlsx (8.3 KB)

PFA Files.

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)

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

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

I’ll try that, thank you.

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.