Vlookup to fetch adjacent value based on earliest date - excel-formula

I need help to write a code to return values for DF using the ID in the lookup table to fetch value that correspond to the latest date where there are duplications

Try a array formula, copy below formula and paste in cell B14 (i'm considering that "DATABASE" are in A1), and press Ctrl + Shift + Enter.
=INDEX(
$D$3:$D$8,
MATCH(
$A14 &
":" &
MAX(
IF(
$A14 = $A$3:$A$8,
$E$3:$E$8,
0
)
),
$A$3:$A$8 &
":" &
$E$3:$E$8,
0
)
)

Related

Excel extract distinct values from multiple columns

I want to extract distinct values from multiple columns.
Example described below :
I have to columns A and B and the desired result is the distinct values between A and B
Use UNIQUE(FILTER()):
=UNIQUE(FILTER(A:B,(A:A<>"")*(B:B<>"")))
Assuming your data is located at [B4:C16] enter this FormulaArray in [E4] then copy to [F4] and [E5:F16]:
= IFERROR( INDEX( B$4:B$16,
MATCH( 1, 1 +
COUNTIFS( $E$3:$E3, $B$4:$B$16, $F$3:$F3, $C$4:$C$16 )
+ ( $B$4:$B$16 = "" ) + ( $C$4:$C$16 = "" ), 0 ) ), "" )
FormulaArray is entered holding down ctrl+shift+enter simultaneously, the formula would be wrapped within { and } if entered correctly.
In Excel 2007, you can use the Advanced Filter
Provide header columns for your data.
I used Country and Year
Set up your criteria range:
A21: Country
A22: <>
B21: Year
B22: <>
Select a cell in your Data range and choose Advanced Filter on the Data tab
In the Advanced Filter dialog
Select Copy to and enter a destination cell in the appropriate area.
Select Unique

Append text to cell value based on dropdown selection

I have a formula to combine several values:
Value in column C
Add 'And' if there is a space
Drop down selection value in column I
Assigned value based on dropdown selection in column I (e.g. B1, C1)
Append B1 or C1 to value in column C, result shown in column M
The formula in column M:
=IF(I15="Truck",CLEAN(SUBSTITUTE(SUBSTITUTE(TRIM(C15),"and ","And"),CHAR(32),"")),IF(I15="Bus",CLEAN(SUBSTITUTE(SUBSTITUTE(TRIM(C15),"and","And"),CHAR(32),"")& "B1"),IF(I15="Car",CLEAN(SUBSTITUTE(SUBSTITUTE(TRIM(C15),"and","And"),CHAR(32),"")),"")& "C1"))
It works except for one tiny part; whenever the value in column C is blank, C1 is populated into column M by default. The value in column M should be blank.
Any thoughts?
The real issue is when I15 is blank. Run through with the "Evaluate Formula" tool, and you should see it, but if you break your code out and format it with indentations/new lines, etc:
=IF(I15="Truck",
CLEAN(
SUBSTITUTE(
SUBSTITUTE(TRIM(C15),"and ","And"), 'Should this be "and" rather than "and " to match the "Bus" and "Car"?
CHAR(32),
""
)
),
IF(I15="Bus",
CLEAN(
SUBSTITUTE(
SUBSTITUTE(TRIM(C15),"and","And"),
CHAR(32),
""
)& "B1"
),
IF(I15="Car",
CLEAN(
SUBSTITUTE(
SUBSTITUTE(TRIM(C15),"and","And"),
CHAR(32),
""
)
), 'Should this bracket be after the "C1" instead of here?
""
)& "C1"
)
)
Now, trace through if I15 is blank: I15 is not "Truck" and I15 is not "Bus", so we get:
=IF(FALSE,
N/A,
IF(FALSE,
N/A,
IF(I15="Car",
CLEAN(
SUBSTITUTE(
SUBSTITUTE(TRIM(C15),"and","And"),
CHAR(32),
""
)
), 'Should this bracket be after the "C1" instead of here?
""
)& "C1"
)
)
Simplify that down, and you get:
IF(I15="Car",
CLEAN(
SUBSTITUTE(
SUBSTITUTE(TRIM(C15),"and","And"),
CHAR(32),
""
)
),
""
)& "C1"
But, I15 is blank, not "Car", so it becomes IF(FALSE, N/A, "") & "C1" - meaning, it will always say "C1" if I15 is not "Bus" or "Truck".
Also, you probably can simplify your code down to =CLEAN(SUBSTITUTE(SUBSTITUTE(TRIM(C15),"and","And"),CHAR(32),"")) & IF(I15="Bus", "B1", IF(I15="Car", "C1", ""))
If you can set up a table somewhere, you can change the IF statement to a VLOOKUP, or if you have a table for the Drop-down values you can use CHOOSE(MATCH(..))

Excel IF Formula to handle more than one possible value in cell

The following is able to handle only "No Access" text in the specified cells.
How can I alter them to handle "Covered" & "Damaged" to display "" (null string) if true, else carry on with formulating.
Column G formula
=IF(OR(L18="No Access",$J18="No Access")," ",(L18-$J18)*1000)
Column I, K & M Formula
=IF(H18 = "No Access","No Access",(H18-$C18)*1000)
Column N formula
=IF(M18="No Access", " ",
IF(ABS(M18)>ABS(F18),"Exceeded PD Level",
IF(AND(ABS(M18)>ABS(E18), ABS(M18)<ABS(F18)),"Exceeded Alert Level",
" ")))
As requested, here's the values I need to handle
Column I,K & M are calculated base on the values in the column before them
Column N refer to value in Column M & compares it with value in Column E & F, displaying various messages to if column M hit the range specified.
(Assuming your alter words are these (Please extend below for any more)):
No Access
Covered
Damaged
There where two approaches I have introduced
1. Please correct your formulas in this form:
Column G formula
=IF(OR(L18="No Access",L18="Covered",L18="Damaged",$J18="No Access",$J18="Covered",$J18="Damaged")," ",(L18-$J18)*1000)
Column I, K & M Formula
=IF(OR(H18 = "No Access",H18 = "Covered",H18="Damaged"),"No Access",(H18-$C18)*1000)
Column N formula
=IF(OR(M18="No Access",M18="Covered",M18="Damaged"), " ",
IF(ABS(M18)>ABS(F18),"Exceeded PD Level",
IF(AND(ABS(M18)>ABS(E18), ABS(M18)<ABS(F18)),"Exceeded Alert Level",
" ")))
2. Use this array form formula to handle any more/ other alters easier:
Follow these 3 steps
Use a helper column, for example column X (It can be hided), and
enter all of your alter words in this column.
Create a Name (Ctrl + F3), for example
Alters and set Refers to field to your helper column range. (for example $X$1:$X$10)
Write this formula in appropriated cells and then press
Alt + Ctrl + Enter to running formula against pressing Enter
Column G formula
=IF(OR(L18=Alters,$J18=Alters)," ",(L18-$J18)*1000)
Column I, K & M Formula
=IF(H18 = Alters,"No Access",(H18-$C18)*1000)
Column N formula
=IF(M18=Alters, " ",
IF(ABS(M18)>ABS(F18),"Exceeded PD Level",
IF(AND(ABS(M18)>ABS(E18), ABS(M18)<ABS(F18)),"Exceeded Alert Level",
" ")))
In this brief form you can Edit, Add or Remove any Alter words as you want in your helper column.

Group on excel rows to a single cell by column id

I have a question regarding excel.
I have two columns, column A has a number and B has country codes. I'm looking for a way to automatically go through 100's thousands of rows to group them so they look like the following...
Is this doable? I'm at a complete loss :(
THE END RESULT
6512 AG,AI,AW,BB,BL,BM,
6513 BQ,BS,BZ,CA,CR
STARTING POINT - column A & B
6512 AG
6512 AI
6512 AW
6512 BB
6512 BL
6512 BM
6513 BQ
6513 BS
6513 BZ
6513 CA
6513 CR
These solutions use a working column named Concatenated Results.
Assuming your data has a header (adjust formulas as required) and is located at B6:C34 (change as required) as in fig below.
Data sorted by ID:
Concatenated Results: Enter this formula in D7.
= CONCATENATE( C7, IF( EXACT( B7, B8 ), "," & D8, "" ) )
ID.Unique: Enter this Array Formula in E7 (FormulaArrays are entered pressing CTRL+SHIFT+ENTER simultaneously, you shall see { and } around the formula if entered correctly)
=IFERROR( INDEX( $B$7:$B$34,
MATCH( 0, COUNTIF( $E6:$E$6, $B$7:$B$34 ), 0 ) * 1 ), "" )
Countries: Enter this formula in F7
=IFERROR(VLOOKUP(E7,$B$6:$J$34,3,0),"")
Copy range D7:F7 till last row of data (i.e. row 34).
Data not sorted: If the data is not sorted enter this formula for the Concatenated Results in D7. All other formulas remain unchanged.
=CONCATENATE( C7,
IF( ISERROR( MATCH( B7, B8:B$35, 0 ) ), "",
"," & VLOOKUP( B7, B8:D$35, 3, 0 ) ) )
Suggest to read the following pages to gain a deeper understanding of the resources used:
Excel functions (alphabetical), Create an array formula, Guidelines and examples of array formulas
Try this out and let me know in case of any queries or if you require detailed explanation.
Step1: Filter the data by column A.
Step2: Make a new column C where use this formula IF(A2=A1,CONCATENATE(B2,",",C1),B2) .
Step3: Make a new column D where use this formula IF(A2=A3," ","REQUIRED_ANS") .
Step4: Filter on column D using ALT + D + F + F and you get you desired output.
My Output:
This is a VBA solution
Assuming your data, excluding header, is located at B7:C34 (change as required).
ID.Unique: Enter this Array Formula in E7 (FormulaArrays are entered pressing CTRL+SHIFT+ENTER simultaneously, you shall see { and } around the formula if entered correctly)
=IFERROR( INDEX( $B$7:$B$34,
MATCH( 0, COUNTIF( $E6:$E$6, $B$7:$B$34 ), 0 ) * 1 ), "" )
Countries: Enter this User Defined Function (UDF) in F7
=Match_Concatenated(E7,$B$7:$C$34)
Copy this UDF code in a VBA Module
Option Explicit
Public Function Match_Concatenated(vValue As Variant, rTrg As Range) As String
Dim sOutput As String
Dim vTrg As Variant, vItm As Variant, lRow As Long
vTrg = rTrg.Value2
For lRow = 1 To UBound(vTrg)
vItm = WorksheetFunction.Index(vTrg, lRow, 0)
If vItm(1) = vValue Then sOutput = sOutput & Chr(44) & vItm(2)
Next
sOutput = Replace(sOutput, Chr(44), vbNullString, 1, 1)
Match_Concatenated = sOutput
End Function
Suggest to read the following pages to gain a deeper understanding of the resources used:
Excel functions (alphabetical),
Create an array formula,
Guidelines and examples of array formulas,
Option Explicit Statement,
Range.Value2 Property (Excel), For...Next Statement,
WorksheetFunction Object (Excel), INDEX function,
If...Then...Else Statement, Replace Function

Excel nested conditional formatting with indirect references

I am working on a MS Excel 2010 spreadsheet where the users want to have some combined conditional formatting.
Individually the functions I want to apply are working correctly, i.e this condition formula works:
= INDIRECT( ADDRESS( IF( ISEVEN( ROW() ), ROW() - 1, ROW() ), 22) ) = "6 Monthly"
As does this:
= OR( COLUMN() = 25, COLUMN() = 28)
But combining the formulae fails to apply any format. No error is returned, but the highlighted area is unaffected on applying the condition:
AND( INDIRECT(ADDRESS(IF(ISEVEN(ROW()), ROW() - 1, ROW()), 22)) = "3 Monthly", OR( COLUMN() = 25, COLUMN() = 28) )
If I want the cells where both conditions are met to be highlighted, what should I enter as the formula?
This works for me:
=(INDIRECT(ADDRESS(IF(ISEVEN(ROW()),ROW()-1,ROW()),22))="3 Monthly")*(OR(COLUMN()=25, COLUMN()=28))
Your conditional formatting formulas seem overly complex to me
Select Y11:Y48 and then hold down CTRL key and also select AB11:AB48 and apply the conditional formatting formula
=$V11="3 Monthly"
Format as required
That will highlight the column Y and AB cells in every row where col V = "3 Monthly" - isn't that the requirement?
Use IF:
=IF(INDIRECT(ADDRESS(IF(ISEVEN(ROW()),ROW()-1, ROW()),22))="3 Monthly",OR(COLUMN()=25,COLUMN()=28),0)
Hope this helps.

Resources