Need help with formula

Potatomr

New Member
Joined
Nov 10, 2017
Messages
6
Hi all,

I need help with a formula, and I'd be super happy if somebody could help me. I have explained the issue in the table below. Maybe it's possible to have a macro or similar that can "go through" the file and automatically correct the dates? What's the best solution you think? The output should be the same as below - but with the correct dates. Thanks on beforehand!

<style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--></style><style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--></style>
LineFIRSTNAMELASTNAMEORDERIDDATE
1AlbertAlbertson10002017-11-01
2AlbertAlbertson15002017-11-01
3AlbertAlbertson15002017-11-01
4BobBobson10002017-11-04
5BobBobson10002017-11-06
6BobBobson15002017-11-04
7CatCatson15002017-11-07
Issue: If FIRSTNAME+LASTNAME has made an order with the same ORDER ID on the same DATE (like line 2 and 3), then postpone DATE by +1 for one of the lines, for example for line nbr 3.

Also, if possible: Postpone DATE by +1 for Line nbr 3 UNLESS the FIRSTNAME+LASTNAME have placed an order on the +1 day with the same ORDER ID - if so then plus +2 days,

<colgroup><col style="width: 100px"><col width="100"><col width="100"><col width="100"><col width="100"></colgroup><tbody>
</tbody>
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Use a helper column and COUNTIFS. Assuming your columns are A,B,C and D, and say you have 100 rows or less, in cell E1 put
Code:
=$D1+COUNTIFS($B$1:$B$100,$B1,$C$1:$C$100,$C1,$D$1:$D$100,$D1)-COUNTIFS($B2:$B$100,$B1,$C2:$C$100,$C1,$D2:$D$100,$D1)-1
Then copy to the bottom.

Getting the $'s right is key. It counts all the rows with the same combination in the table, then deducts how many are below so in this example it would go in col E

2017-11-04 + 0
2017-11-04 + 1

if you had 5 it would go

2017-11-04 + 0
2017-11-04 + 1
2017-11-04 + 2
2017-11-04 + 3
2017-11-04 + 4

I can't get into excel to test it right now but try it, if it doesn't work you may have to tweak it.
 
Last edited:
Upvote 0
I would adjust the suggested formula slightly so it does a progressive count, rather than a full count...
=$D1+COUNTIFS($B$1:$B1,$B1,$C$1:$C1,$C1,$D$1:$D1,$D1)-1
 
Upvote 0
Hi,

Thank you both for your answers. Unfortunately I can't get it to work. I have the data as following = A = LAST NAME, Column B = FIRST NAME, Column C = Order ID and column D = date. Although it gives me an error and I can't figure out why (just says something is wrong with the formula). Is it due to it being mixed text and numbers or something?
 
Upvote 0
Okay the problem is solved and the formula works, I needed ; instead of ,. Thanks a lot!

Although, do you have any ideas to solve the problem I mentioned as an additional problem in the first post? If Line number 2 is the same as the date it's being postponed to (line number 3, 2/11) the formula should postpone line number 2 one extra day to 3/11. What is possible is of course to do this help column two or three times based on the "new date", but if you have any ideas of how to tweak the formula to take that into consideration it would be very appreciated.

FIRSTNAMELASTNAMEORDERIDOLD DATENEW DATE
AlbertAlbertson150001-11-201701-11-2017
AlbertAlbertson150001-11-201702-11-2017
AlbertAlbertson150002-11-201702-11-2017

<tbody>
</tbody>
 
Upvote 0
The formula I suggested in #3 should do that for you?


Unfortunately it doesn't seem like it's taking that into consideration. I tried on the following example:

FIRST NAMELAST NAMEIDOLD DATENEW DATE
ALBERTALBERTSON150014-11-201714-11-2017
ALBERTALBERTSON150014-11-201715-11-2017
ALBERTALBERTSON150015-11-201715-11-2017
ALBERTALBERTSON150015-11-201716-11-2017
ALBERTALBERTSON150015-11-201717-11-2017
ALBERTALBERTSON150015-11-201718-11-2017
ALBERTALBERTSON150016-11-201716-11-2017
ALBERTALBERTSON150016-11-201717-11-2017

<tbody>
</tbody>

What do you think?
 
Upvote 0
My suggestion does work. From the looks of it, your "date" is not really a date, it is just text looking like a date. Below I have I converted to real dates using Text2Column
A​
B​
C​
D​
E​
F​
1​
FIRST NAMELAST NAMEIDOLD DATENEW DATEMine
2​
ALBERTALBERTSON
1500​
14-11-2017​
14-11-2017​
14-11-2017​
3​
ALBERTALBERTSON
1500​
14-11-2017​
15-11-2017
15-11-2017​
4​
ALBERTALBERTSON
1500​
15-11-2017​
15-11-2017
15-11-2017​
5​
ALBERTALBERTSON
1500​
15-11-2017​
16-11-2017
16-11-2017​
6​
ALBERTALBERTSON
1500​
15-11-2017​
17-11-2017
17-11-2017​
7​
ALBERTALBERTSON
1500​
15-11-2017​
18-11-2017​
18-11-2017​
8​
ALBERTALBERTSON
1500​
16-11-2017​
16-11-2017
16-11-2017​
9​
ALBERTALBERTSON
1500​
16-11-2017​
17-11-2017
17-11-2017​
F2=$D2+COUNTIFS($B$2:$B2,$B2,$C$2:$C2,$C2,$D$2:$D2,$D2)-1
copied down
 
Upvote 0

Forum statistics

Threads
1,215,684
Messages
6,126,199
Members
449,298
Latest member
Jest

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