Derive column value based on multiple criteria

adityatandel

Board Regular
Joined
Aug 10, 2007
Messages
71
I have the following data in excel. I would like to derive the "Action" column for a "Person ID" based on the Y or N indicators in the "Value" column and what's in the "Month" column

Book5
ABCD
1Person IDValueMonthAction
21N1/1/231st action
32Y1/1/23
41N2/1/232nd action
52N2/1/231st action
62Y3/1/23
73N3/1/231st action
82N4/1/231st action
93Y4/1/23
104Y4/1/23
Sheet1



For a Person ID, if the value is Y then action should be empty
If for a Person ID, the value is N then:

  1. Check the last record for that person ID and whether the month is one prior to the current month
    1. If a record exists for the person ID in the prior month, then check the value for that record
      • If the value is N then action column should be populated with "2nd action"
      • If the value is Y then action should be "1st action"
    2. If the person ID is not present in the prior month then action should be "1st action"
Once a person ID is flagged for "2nd action" that person's record will not be included in the next month

I have given some examples below:
  1. For Person ID 1
    1. In 1/1/23 since the value is N action is "1st action"
    2. In 2/1/23 value was N and in the prior month (1/1/23) the value was also N, action is "2nd action"
  2. For Person ID 2
    1. In 1/1/23 since value is Y action is empty
    2. In 2/1/23 since value is N and value in the prior month is Y, action is "1st action"
    3. In 3/1/23 since value is Y action is empty
    4. In 4/1/23 since value is N and value in 3/1/23 is Y then "1st action"
  3. For Person ID 3
    1. In 3/1/23 since value is N and there is no record for this ID in the prior month (2/1/23), action is "1st action"
    2. In 4/1/23 since value is Y action is empty

Date format is mm/dd/yy
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Excel Formula:
=IF(B2="N",SUMPRODUCT(--($A$2:A2=A2)*--($B$2:B2="N")*--(YEAR($C$2:C2)=YEAR(C2)*--(MONTH($C$2:C2)=MONTH(C2)))&". action","")
 
Upvote 0
Thank you but this solution worked for me.

=IF(B2="Y","",CHOOSE(SUMPRODUCT((A$2:A2=A2)*($B$2:B2="N")*(DATEDIF($C$2:C2,C2,"YM")<=1)),"1st ","2nd ","3rd ","4th ")&"action")
Paste this in E2 and copied down
 
Upvote 0

Forum statistics

Threads
1,224,744
Messages
6,180,696
Members
452,994
Latest member
Janick

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