Splitting rows in a table based on date fields.

Tom123456

New Member
Joined
Feb 19, 2016
Messages
34
Hey,

I have a list of bookings that have a start & end date and a amount.

I need to split the table so that each month has it's own line and % amount

For example before it would look like this.

[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Booking[/TD]
[TD]Start Date[/TD]
[TD]End Date[/TD]
[/TR]
[TR]
[TD]Booking 1[/TD]
[TD]01/08/2017[/TD]
[TD]30/11/2017[/TD]
[/TR]
[TR]
[TD]Booking 1[/TD]
[TD]01/10/2017[/TD]
[TD]30/11/2017[/TD]
[/TR]
[TR]
[TD]Booking 2[/TD]
[TD]11/08/2017[/TD]
[TD]30/09/2017[/TD]
[/TR]
[TR]
[TD]Booking 2[/TD]
[TD]11/08/2017[/TD]
[TD]30/09/2017[/TD]
[/TR]
[TR]
[TD]Booking 3[/TD]
[TD]07/08/2017[/TD]
[TD]31/08/2017[/TD]
[/TR]
</tbody>[/TABLE]










but i need to work out how to split it to become like so

[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Booking[/TD]
[TD]Start Date[/TD]
[TD]End Date[/TD]
[/TR]
[TR]
[TD]Booking 1[/TD]
[TD]01/08/2017[/TD]
[TD]31/08/2017[/TD]
[/TR]
[TR]
[TD]Booking 1[/TD]
[TD]01/09/2017[/TD]
[TD]30/09/2017[/TD]
[/TR]
[TR]
[TD]Booking 2[/TD]
[TD]11/08/2017[/TD]
[TD]31/08/2017[/TD]
[/TR]
[TR]
[TD]Booking 2[/TD]
[TD]01/09/2017[/TD]
[TD]30/09/2017[/TD]
[/TR]
[TR]
[TD]Booking 2[/TD]
[TD]11/08/2017[/TD]
[TD]31/08/2017[/TD]
[/TR]
[TR]
[TD]Booking 2[/TD]
[TD]01/09/2017[/TD]
[TD]30/09/2017[/TD]
[/TR]
[TR]
[TD]Booking 3[/TD]
[TD]07/08/2017[/TD]
[TD]31/08/2017[/TD]
[/TR]
</tbody>[/TABLE]













[TABLE="width: 416"]
<tbody>[TR]
[/TR]
[TR]
[/TR]
[TR]
[TD]I've added columns that calculates the number of days/month in each row and the amount per day but don't know where to start with using this information to split like this- if anyone can point me in the right direction it would be a great help!

Cheers,
Tom[/TD]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Here is how I would do it.

I would use VBA, first sorting my table, then creating a record set and looping through it, creating the records that I need.
I cannot really think of another way to do it.

If that is an acceptable option, let me know, and I will see if I can whip up some code for you.
 
Upvote 0
Hi Joe,

This would be an acceptable option - would you be able to provide some VBA code for me to test with?

Thanks,

Tom
 
Upvote 0
Give me a little time to whip something up. It has been a while since I have done something like this, so I need to consult my notes.

A few questions for you though:
- What is the exact name of your Table and Fields?
- What I am envisioning will create the records in a new Table. Is that OK?
- Can you explain why some bookings appear to be duplicated or overlapping (for example, Bookings 1 and 2 in your original example)?
- Are there other fields in this table which need to be populated too?
 
Last edited:
Upvote 0
- What is the exact name of your Table and Fields?

Table is called 'Data' Fields are shown in this image (URL below)

https://pasteboard.co/GLf2Nff.png

What I am envisioning will create the records in a new Table. Is that OK?

A new table is ok

- Can you explain why some bookings appear to be duplicated or overlapping (for example, Bookings 1 and 2 in your original example)?

Sorry this is an error on my part when providing the sample data - Booking 1 should of been split into 4 lines (Aug,Sept,Oct,November) - this image should explain it correctly

https://pasteboard.co/GLf63oJ.png

- Are there other fields in this table which need to be populated too?

Yes they all need to be duplicated identically (except the start/end date fields & the amount field which i need to split based on days in each of the new rows - but i left this out as to not over complicate my starting issue)




GLf2Nff.png
 
Last edited:
Upvote 0
Sorry this is an error on my part when providing the sample data - Booking 1 should of been split into 4 lines (Aug,Sept,Oct,November) - this image should explain it correctly
Unfortunately, my work's Corporate Security Policy blocks those type of image sites, so I cannot see any of your image links.
Can you post a new data sample, like you did in your original post?

Yes they all need to be duplicated identically (except the start/end date fields & the amount field which i need to split based on days in each of the new rows - but i left this out as to not over complicate my starting issue)
There is a real danger in oversimplifying the issue, and that is you will probably get an oversimplified response (since it is based on your oversimplified question) that will not work for you, unless you are savvy enough to know how to update the VBA code to do what you want. I see it happen all the time. People get a response, and then respond that it will not work for them because ..., and they list a bunch of new conditions that they did not mention originally.

So, unless you feel comfortable enough with VBA and DAO Recordsets to update (yourself) the code I would write based on your original requirements, I think you will want to mention these other fields, and if something has to happen to this Amount field, explain that logic too.
 
Upvote 0
Hi Joe,

Apologies for oversimplifying the issue.

Table is called Data and it has the following fields and a number of rows that follow the format shown below

[TABLE="width: 500"]
<tbody>[TR]
[TD]Reference[/TD]
[TD]Line ID[/TD]
[TD]Sales Person[/TD]
[TD]Customer[/TD]
[TD]Start Date[/TD]
[TD]End Date[/TD]
[TD]Primary Contact[/TD]
[TD]Brand Family[/TD]
[TD]Product Platform[/TD]
[TD]Product Type[/TD]
[TD]Product Name[/TD]
[TD]Unit of Measure[/TD]
[TD]Amount[/TD]
[TD]Contract Month[/TD]
[TD]Customer Contract Date
[/TD]
[TD]Amount Currency[/TD]
[TD]Navision ID[/TD]
[/TR]
[TR]
[TD]DCON-66606[/TD]
[TD]338768[/TD]
[TD]Chris[/TD]
[TD]Axa - London[/TD]
[TD]02/08/2017[/TD]
[TD]25/11/2017[/TD]
[TD]Phil[/TD]
[TD]Insurance[/TD]
[TD]Digital[/TD]
[TD]Video[/TD]
[TD]Bespoke[/TD]
[TD]Exclusive[/TD]
[TD]£20,0000[/TD]
[TD]Aug 2017[/TD]
[TD]07/08/2017[/TD]
[TD]GBP[/TD]
[TD]WB125[/TD]
[/TR]
[TR]
[TD]DCON-66606[/TD]
[TD]338770[/TD]
[TD]Chris[/TD]
[TD]Axa - London[/TD]
[TD]01/10/2017[/TD]
[TD]30/11/2017[/TD]
[TD]Phil[/TD]
[TD]Insurance[/TD]
[TD]Digital[/TD]
[TD]Lead Generation[/TD]
[TD]Hound[/TD]
[TD]Leads[/TD]
[TD]£5000[/TD]
[TD]Aug 2017[/TD]
[TD]07/08/2017[/TD]
[TD]GBP[/TD]
[TD]WB126[/TD]
[/TR]
</tbody>[/TABLE]

For every row in this table i need the VBA to look at the start & end date fields and if the period spans more then a single month it needs to do 2 things.

1) Duplicate the row and it's information (exlc start/end dates which change) by the number of months in that period
2) Calculate & update the new amount for the row (the new amounts on the duplicated line should sum to the original amount)

The new amount in these rows is calculated by

Original Line Amount / Days in Period = DailyRevenueRate

Days in New period * DailyRevenueRate = New Amount

Therefore the first row from above would be split into 4 rows with the amount value split by the days in it's period

[TABLE="width: 500"]
<tbody>[TR]
[TD]DCON-66606[/TD]
[TD]338768[/TD]
[TD]Chris[/TD]
[TD]Axa - London[/TD]
[TD]02/08/2017[/TD]
[TD]31/08/2017[/TD]
[TD]Phil[/TD]
[TD]Insurance[/TD]
[TD]Digital[/TD]
[TD]Video[/TD]
[TD]Bespoke[/TD]
[TD]Exclusive[/TD]
[TD]£5000[/TD]
[TD]Aug 2017[/TD]
[TD]07/08/2017[/TD]
[TD]GBP[/TD]
[TD]WB125[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 500"]
<tbody>[TR]
[TD]DCON-66606[/TD]
[TD]338768[/TD]
[TD]Chris[/TD]
[TD]Axa - London[/TD]
[TD]01/09/2017[/TD]
[TD]30/09/2017[/TD]
[TD]Phil[/TD]
[TD]Insurance[/TD]
[TD]Digital[/TD]
[TD]Video[/TD]
[TD]Bespoke[/TD]
[TD]Exclusive[/TD]
[TD]£5172.314[/TD]
[TD]Aug 2017[/TD]
[TD]07/08/2017[/TD]
[TD]GBP[/TD]
[TD]WB125[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 500"]
<tbody>[TR]
[TD]DCON-66606[/TD]
[TD]338768[/TD]
[TD]Chris[/TD]
[TD]Axa - London[/TD]
[TD]01/10/2017[/TD]
[TD]31/10/2017[/TD]
[TD]Phil[/TD]
[TD]Insurance[/TD]
[TD]Digital[/TD]
[TD]Video[/TD]
[TD]Bespoke[/TD]
[TD]Exclusive[/TD]
[TD]£5344.83[/TD]
[TD]Aug 2017[/TD]
[TD]07/08/2017[/TD]
[TD]GBP[/TD]
[TD]WB125[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 500"]
<tbody>[TR]
[TD]DCON-66606[/TD]
[TD]338768[/TD]
[TD]Chris[/TD]
[TD]Axa - London[/TD]
[TD]01/11/2017[/TD]
[TD]25/11/2017[/TD]
[TD]Phil[/TD]
[TD]Insurance[/TD]
[TD]Digital[/TD]
[TD]Video[/TD]
[TD]Bespoke[/TD]
[TD]Exclusive[/TD]
[TD]£4482.75862
[/TD]
[TD]Aug 2017[/TD]
[TD]07/08/2017[/TD]
[TD]GBP[/TD]
[TD]WB125[/TD]
[/TR]
</tbody>[/TABLE]

And the 2nd Row would be split into 2 rows in a similar manner
 
Last edited:
Upvote 0
OK. Give me a little time with this, and I will see if I can get something to you later today.
 
Upvote 0
A few more things I just noticed...

Going back to your example, when you show it broken out, you have different Amounts for August and September (5000 and 5172.314).
However, shouldn't they be the same? Aren't they both 30 days (2/8/17-31/8/17 and 1/9/17-30/9/17 are both 30 days)?

Also, are we concerned about rounding differences not adding up to exactly the original amount (maybe be off by a fraction)?
 
Upvote 0
They should be the same - some bad mental math on my part adding days in a month

Line 1 has a 116 days in total split as below

[TABLE="width: 500"]
<tbody>[TR]
[TD]Amount
[/TD]
[TD]Days
[/TD]
[/TR]
[TR]
[TD]5172.413793
[/TD]
[TD]30
[/TD]
[/TR]
[TR]
[TD]5172.413793
[/TD]
[TD]30
[/TD]
[/TR]
[TR]
[TD]5344.827586
[/TD]
[TD]31
[/TD]
[/TR]
[TR]
[TD]4310.344828
[/TD]
[TD]25
[/TD]
[/TR]
</tbody>[/TABLE]

I am concerned about rounding differences that mean the sum of the lines do not equal the amounts but liberal on how to resolve (eg add the correct fractional amount to any line)

Cheers,
Tom
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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