Adding COUNT to records

abesimpson

Active Member
Joined
May 3, 2003
Messages
435
I import a text file of several million records into Access every month .
Each record has a date field, and a value field. The database is sorted first on date, then on value. Each date has many values, but there is no fixed number of records per date.

The sorted database looks like this:
Date1, Value1
Date1, Value2
Date1, Value3
Date1, Value4
Date2, Value1
Date2, Value2
Date2, Value3
Date3, Value1
Date3, Value2
Date4, Value1
etc.

I need to add a count per record, to get this:,
Date1, Value1, Count1
Date1, Value2, Count2
Date1, Value3, Count3
Date1, Value4, Count4
Date2, Value1, Count1
Date2, Value2, Count2
Date2, Value3, Count3
Date3, Value1, Count1
Date3, Value2, Count2
Date4, Value1, Count1
etc


I habve NO idea how to do this. Any help will be appreciated.

abe
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi,

after you have imported your text file into a temporary table, you could insert all data from a single day into a table with an autovalue-column. So you have numbered each row for one day. And then you insert the whole data from this single day into your main-table.
Then you have to do this for every other day. I would make a VBA-Code which automatically does this, otherwise it would take too much time ...

Perhaps anyone else has an other idea.
 
Upvote 0
abe

I'm unsure exactly what you mean by a count per record.

Do you want to count the dates?

If so you can you not create a Totals query based on the table you have imported.

It would have the date field twice, once as Group By and once as Count.
 
Upvote 0
Clairification

Perhaps count is the incorrect term. What I am trying to do is to number each date range group, number 1 to n.

Given the number of records, Excell is out of the question.

Any suggestions as to how VBA code would be written would be aprrectiated.

Thanks

abe
 
Upvote 0
Hi abe

I think this can be done with a ranking query. If I understand your example correctly, you would like to group by date, sort by value and then assign a sequential number, starting at 1 for each new date. Assuming the values within each date are unique then a ranking query will work fine, if not then the rankings will look a bit funny.

Here is an example of a ranking within group. You won't need any criteria per the example post.

If you get stuck then post back into this topic.

HTH, Andrew. :)
 
Upvote 0

Forum statistics

Threads
1,215,002
Messages
6,122,652
Members
449,092
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top