Hi all,
This is a problem I've been grapping with for a few months on and off and I can't seem to crack it...
I have a CSV list of call detail records and a list of long distance rates and I need to be able to match the rate to the phone number based on the longest prefix match.
Here is sample of what the rate table looks like:
[TABLE="width: 400"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]destination
[/TD]
[TD="align: right"]prefix
[/TD]
[TD="align: right"]rate
[/TD]
[/TR]
[TR]
[TD]Finland - Mobile
[/TD]
[TD="align: right"]3584571[/TD]
[TD="align: right"]0.34[/TD]
[/TR]
[TR]
[TD]Finland - NGN - personal[/TD]
[TD="align: right"]35871[/TD]
[TD="align: right"]0.1[/TD]
[/TR]
[TR]
[TD]Finland - Other
[/TD]
[TD="align: right"]3589315980[/TD]
[TD="align: right"]0.1[/TD]
[/TR]
[TR]
[TD]Finland - Sonera Mobile[/TD]
[TD="align: right"]35840[/TD]
[TD="align: right"]0.34[/TD]
[/TR]
[TR]
[TD]Finland - Sonera Mobile[/TD]
[TD="align: right"]35842[/TD]
[TD="align: right"]0.34[/TD]
[/TR]
[TR]
[TD]Finland[/TD]
[TD="align: right"]358[/TD]
[TD="align: right"]0.1[/TD]
[/TR]
[TR]
[TD]Finland[/TD]
[TD="align: right"]35819[/TD]
[TD="align: right"]0.1[/TD]
[/TR]
[TR]
[TD]Finland[/TD]
[TD="align: right"]35829[/TD]
[TD="align: right"]0.1[/TD]
[/TR]
[TR]
[TD]Finland[/TD]
[TD="align: right"]3587[/TD]
[TD="align: right"]0.1[/TD]
[/TR]
[TR]
[TD]Finland[/TD]
[TD="align: right"]35870[/TD]
[TD="align: right"]0.1[/TD]
[/TR]
[TR]
[TD]Finland[/TD]
[TD="align: right"]3589[/TD]
[TD="align: right"]0.1[/TD]
[/TR]
[TR]
[TD]France - Mobile Bouygues
[/TD]
[TD="align: right"]336003[/TD]
[TD="align: right"]0.47[/TD]
[/TR]
</tbody>[/TABLE]
The other table I have looks like this:
[TABLE="width: 178"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]To
[/TD]
[TD]Duration[/TD]
[/TR]
[TR]
[TD="align: right"]14734334000
[/TD]
[TD="align: right"]0:19:47[/TD]
[/TR]
[TR]
[TD="align: right"]3222735856
[/TD]
[TD="align: right"]0:02:09[/TD]
[/TR]
[TR]
[TD="align: right"]35622458106
[/TD]
[TD="align: right"]0:06:47[/TD]
[/TR]
[TR]
[TD="align: right"]35622458130
[/TD]
[TD="align: right"]0:03:41
[/TD]
[/TR]
</tbody>[/TABLE]
The first table has about 150,000 rows worth of prefixes.
My ultimate goal would be to generate a third table that would append the rate to a new column like this (not real data):
[TABLE="width: 178"]
<tbody>[TR]
[TD]To
[/TD]
[TD]Duration
[/TD]
[TD] Cost
[/TD]
[/TR]
[TR]
[TD="align: right"]14734334000
[/TD]
[TD="align: right"]0:19:47
[/TD]
[TD="align: right"]2.54
[/TD]
[/TR]
[TR]
[TD="align: right"]3222735856
[/TD]
[TD="align: right"]0:02:09[/TD]
[TD="align: right"]0.54
[/TD]
[/TR]
[TR]
[TD="align: right"]35622458106
[/TD]
[TD="align: right"]0:06:47[/TD]
[TD="align: right"]...
[/TD]
[/TR]
[TR]
[TD="align: right"]35622458130
[/TD]
[TD="align: right"]0:03:41
[/TD]
[TD="align: right"]...
[/TD]
[/TR]
</tbody>[/TABLE]
My biggest sticking point is finding a formula or set of formulas that will allow a longest prefix match in Excel. The closest I came was to make an insanely large spreadsheet with multiple columns with prefix length 1, 2, 3,4, 5, 6 and so on and then grabbing the largest value but it was insanely messy and incredibly inefficient (and didn't work properly).
Hopefully some guru here can help with this one!
This is a problem I've been grapping with for a few months on and off and I can't seem to crack it...
I have a CSV list of call detail records and a list of long distance rates and I need to be able to match the rate to the phone number based on the longest prefix match.
Here is sample of what the rate table looks like:
[TABLE="width: 400"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]destination
[/TD]
[TD="align: right"]prefix
[/TD]
[TD="align: right"]rate
[/TD]
[/TR]
[TR]
[TD]Finland - Mobile
[/TD]
[TD="align: right"]3584571[/TD]
[TD="align: right"]0.34[/TD]
[/TR]
[TR]
[TD]Finland - NGN - personal[/TD]
[TD="align: right"]35871[/TD]
[TD="align: right"]0.1[/TD]
[/TR]
[TR]
[TD]Finland - Other
[/TD]
[TD="align: right"]3589315980[/TD]
[TD="align: right"]0.1[/TD]
[/TR]
[TR]
[TD]Finland - Sonera Mobile[/TD]
[TD="align: right"]35840[/TD]
[TD="align: right"]0.34[/TD]
[/TR]
[TR]
[TD]Finland - Sonera Mobile[/TD]
[TD="align: right"]35842[/TD]
[TD="align: right"]0.34[/TD]
[/TR]
[TR]
[TD]Finland[/TD]
[TD="align: right"]358[/TD]
[TD="align: right"]0.1[/TD]
[/TR]
[TR]
[TD]Finland[/TD]
[TD="align: right"]35819[/TD]
[TD="align: right"]0.1[/TD]
[/TR]
[TR]
[TD]Finland[/TD]
[TD="align: right"]35829[/TD]
[TD="align: right"]0.1[/TD]
[/TR]
[TR]
[TD]Finland[/TD]
[TD="align: right"]3587[/TD]
[TD="align: right"]0.1[/TD]
[/TR]
[TR]
[TD]Finland[/TD]
[TD="align: right"]35870[/TD]
[TD="align: right"]0.1[/TD]
[/TR]
[TR]
[TD]Finland[/TD]
[TD="align: right"]3589[/TD]
[TD="align: right"]0.1[/TD]
[/TR]
[TR]
[TD]France - Mobile Bouygues
[/TD]
[TD="align: right"]336003[/TD]
[TD="align: right"]0.47[/TD]
[/TR]
</tbody>[/TABLE]
The other table I have looks like this:
[TABLE="width: 178"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]To
[/TD]
[TD]Duration[/TD]
[/TR]
[TR]
[TD="align: right"]14734334000
[/TD]
[TD="align: right"]0:19:47[/TD]
[/TR]
[TR]
[TD="align: right"]3222735856
[/TD]
[TD="align: right"]0:02:09[/TD]
[/TR]
[TR]
[TD="align: right"]35622458106
[/TD]
[TD="align: right"]0:06:47[/TD]
[/TR]
[TR]
[TD="align: right"]35622458130
[/TD]
[TD="align: right"]0:03:41
[/TD]
[/TR]
</tbody>[/TABLE]
The first table has about 150,000 rows worth of prefixes.
My ultimate goal would be to generate a third table that would append the rate to a new column like this (not real data):
[TABLE="width: 178"]
<tbody>[TR]
[TD]To
[/TD]
[TD]Duration
[/TD]
[TD] Cost
[/TD]
[/TR]
[TR]
[TD="align: right"]14734334000
[/TD]
[TD="align: right"]0:19:47
[/TD]
[TD="align: right"]2.54
[/TD]
[/TR]
[TR]
[TD="align: right"]3222735856
[/TD]
[TD="align: right"]0:02:09[/TD]
[TD="align: right"]0.54
[/TD]
[/TR]
[TR]
[TD="align: right"]35622458106
[/TD]
[TD="align: right"]0:06:47[/TD]
[TD="align: right"]...
[/TD]
[/TR]
[TR]
[TD="align: right"]35622458130
[/TD]
[TD="align: right"]0:03:41
[/TD]
[TD="align: right"]...
[/TD]
[/TR]
</tbody>[/TABLE]
My biggest sticking point is finding a formula or set of formulas that will allow a longest prefix match in Excel. The closest I came was to make an insanely large spreadsheet with multiple columns with prefix length 1, 2, 3,4, 5, 6 and so on and then grabbing the largest value but it was insanely messy and incredibly inefficient (and didn't work properly).
Hopefully some guru here can help with this one!