maxifs returning 00/00/1900 as date for blank date - excel

I want latest dates corresponding to each unique ID mentioned in sheet1. When no date is mentioned against an ID , I am getting 00/01/1900 as the latest date instead of blank. How to fix this
Sheet1 (input data sheet)
A B
2 ID Date1
3 ID1 20/11/2020
4 ID2 18/10/2019
5 ID1 29/01/2018
6 ID2 10/10/2021
7 ID3
Formula used in sheet2 (to caluclate latest date for each ID)
A B
2 IDSheet2 Latestdate
3 ID2 =maxifs('Sheet1'!B:B,'Sheet1'!$A:$A,"="&A2)
4 ID1
5 ID3
OUTPUT obtained
A B
2 IDSheet2 Latestdate
3 ID2 10/10/2021
4 ID1 20/11/2020
5 ID3 00/01/1900 (want a blank here)
Issue:
I am getting 00/01/1900 as date when there is a blank date corresponding to an ID. How to get blank against ID3 here for instance instead of 00/01/1900

Two current options:
IF formula
This lets you check if the max would be 0
=IF(MAXIFS(Sheet1!B:B,Sheet1!$A:$A,A2)=0, "", MAXIFS(Sheet1!B:B,Sheet1!$A:$A,A2))
Cell formatting
On the relevant cells, change cell formatting (CTRL+1), choose custom and enter dd/mm/yyyy;;
Doing this requires no formula change.
(bonus for future Excel release - IF with LET)
In an upcoming release there will be the LET function where you only define the variable once for improved performance and easier reading. The formula would be: =LET(max_value,MAXIFS(Sheet1!B:B,Sheet1!$A:$A,A2),IF(max_value=0,"",max_value))

use the reciprocal or the reciprocal:
=IFERROR(1/(1/maxifs('Sheet1'!B:B,'Sheet1'!$A:$A,"="&A2)),"")

Try it
if(day(maxifs('Sheet1'!B:B,'Sheet1'!$A:$A,"="&A2)<1,"",maxifs('Sheet1'!B:B,'Sheet1'!$A:$A,"="&A2))

Related

lookup values between date range

Good day,
I'm trying to use V&hLookup to get my values but I'm not sure if I'm using the correct formula.
I'm working of 2 sets of data (sheet1 and sheet2). Sheet1 the data is vertical (e.g. unique identifiers and dates) and sheet2 the dates are horizonal and values below. Both sheets have unique identifiers Vertically.
Question: On sheet1, I need to look up the values from sheet2, if there is not values then the formula must look at the next available value after the start date? I got the values as examples on sheet1 as to what it should be
E.g.
Sheet1
Key
Dates
Values
12345
01/01/2020
120.00
678910
01/02/2020
150.00
789456
01/03/2020
110.00
Sheet2
Key
01/01/2020
01/02/2020
03/04/2020
12345
120.00
0.00
150.00
678910
0.00
120.50
130.00
789456
160.00
120.00
110.00
Thanks a million.
Edited answer: suggested solution using MATCH(search_value,match_range,1) in combination with INDEX gave wrong results.
The following should do:
=INDEX(Sheet2!$A$1:$D$4,
MATCH(A5,Sheet2!$A$1:$A$4,0),
MATCH(
MIN(IF(Sheet2!$B$1:$D$1>=B5,Sheet2!$B$1:$D$1,"")),
Sheet2!$A$1:$D$1,
0))
Enter with ctrl+shift+enter in older Excel versions.
The row is found matching the Key-value and the column is found by matching the column where the date value in Sheet2 headers greater than or equal to search date value.
And when using Tables:
=INDEX(Table3,
MATCH([#Key],Table3[Key],0),
MATCH(
MIN(IFERROR(IF(--Table3[#Headers]>=[#Dates],--Table3[#Headers]),9^9)),
--Table3[#Headers],
0))
Where I needed to workaround the date headers becoming text instead of number values by adding leading -- to the value/range.

Highlight cells with different values based on ID

I have two columns, ID and Date. I need to highlight the rows for an ID if that ID does not have the same dates in all of the rows for that ID. e.g.:
ID Date
1 1/1/2020
1 1/1/2020
1 1/1/2020
2 2/2/2020
2 2/16/2020
2 2/2/2020
In the case of ID = 1, it shouldn't highlight anything because all of the rows for the ID = 1 have the same dates, but in the ID = 2, there's different dates (There's 2 '2/2/2020' and 1 "2/16/2020') so it should highlight all of the rows of the ID = 2.
Please note that there might be cases in which different IDs use the same set of dates. e.g.:
ID Date
1 1/1/2020
1 1/1/2020
1 1/1/2020
2 1/1/2020
2 1/16/2020
2 1/1/2020
In the case above, it should highlight only the rows that have ID = 2 since there's different dates for that ID (2 '1/1/2020' and 1 '1/16/2020').
Edit: This was achieved, without creating a macro, by using Conditional Formatting.
In the ID case of 1, it shouldn't highlight anything but in the ID 2, there's different dates so it should highlight all of the rows for that ID.
No VBA required. Use Home Tab - Conditional Formatting
Select your range and use Use a formula to determine which cells to format and use the below formula. I am taking $A$2:$B$7 for demonstration purpose. Change as applicable.
=COUNTIF($A$2:$A$7,$A2)<>COUNTIF($B$2:$B$7,$B2)
If you still want VBA then simply record a macro and perform the above steps. You will get the code which you can edit to suit your needs.
#SiddharthRout Thank you for your help! This sounds like it would work but what if 2 IDs use the same date? Lets say that by coincidence 2 IDs must have the same date, then the conditional format would highlight all of the cells regardless of the ID. ID Date 1 2/2/2020 1 2/2/2020 1 2/2/2020 2 2/2/2020 2 2/3/2020 2 2/2/2020 Do you think this can be avoided using conditional format as well? – Michael Murillo 14 hours ago
In such a case, the above formula will not work. Try the conditional formatting with this formula
=COUNTIF($A$2:$A$7,$A2)<>SUMPRODUCT(IF(CONCATENATE($A$2:$A$7,"--",$B$2:$B$7)=$A2&"--"&$B2,1,0))
What this formula does is checks for the count of ID in Column A and matches it with count of text created by concatenation of Column A and Column B.

retrieve column header from max value row

I have two spreadsheets, one containing a database (sheet 1) and on the other one (sheet2) I'd like to retrieve the header of the column tha contains the max value between rows, given a certain ID.
Sheet 1:
A B C D E
1 ID 2020 2021 2022 2023
2 N-16 0,00 1550,00 1750,00 2200,00
3 N-23 0,00 0,00 0,00 20010,00
4 N-53 100,00 60,00 20,00 80,00
Sheet 2:
A B C
1 ID Max Value Year
2 N-53 100,00
3 N-16 2200,00
4 N-23 20010,00
But it should look like this:
A B C
1 ID Max Value Year
2 N-53 100,00 2020
3 N-16 2200,00 2023
4 N-23 20010,00 2023
I can´t seem to get the year on column C unless I know which row the ID I´d like to match from sheet2 is located on sheet1. Since this database is updated constantly, the IDs are into a random order.
=INDEX(Sheet1!$B$1:$E$1;MATCH(MAX(INDEX((Sheet1!$A$2:$A$4=$A2)*Sheet1!$B$2:$E$4;0));Sheet1!$A$4:$E$4;0))
Is there a way I can modify the last part of the formula to look for every row on sheet1, find the matching ID from sheet2, look for the row with the matching ID on sheet1 and find Max Value, then return the header with the corresponding year?
Thanks in advance.
You can use this array formula :
{=INDEX($B$1:$E$1;1;MATCH(MAX(INDEX(($A$2:$A$4=$A13)*$B$2:$E$4;0));OFFSET($B$2:$E$4;MATCH(A13;$A$2:$A$4;0)-1;0;1;);0))}
I kept most of your formula, but the lookup array for your MATCH is calculated with the OFFSET function. This will also work when the ID's are not sorted.
I put all data on the same worksheet for testing, so you'll just have to change the references.
I have not split on two pages but the method should be analogus to what you want.
I have changed the formulas according to your suggestion.
=MAX(INDEX($B$2:$E$4;MATCH(A8;$A$2:$A$4;0);0))
=INDEX($B$1:$E$1;MATCH(B8;INDEX($B$2:$E$4;MATCH(A8;$A$2:$A$4;0););0))

Match criteria between two tables to find maximum date within a list

I have 2 tables of data, one is only 5 columns and the second is 100s of columns, but in simplistic terms they have the formatting below. Both are hundreds of rows long.
Table 1 (is sorted ascending, all columns)
A B C D E
1 Date TeamF Trans Name TeamT
2 date1 teamF1 trans1 name1 teamT1
3 date2 teamF2 trans2 name2 teamT2
4 date3 teamF3 trans3 name3 teamT3
5 date4 teamF4 trans4 name4 teamT4
6 date5 teamF5 trans5 name5 teamT5
Table 2 (not sorted in any manner)
A B C D E F G ,etc.
1 Team Game Date Opp NameA NameB NameC ,etc...
2 team1 game1 date1 opp1 statsA1 statsB1 statsC1 ,etc...
3 team2 game2 date2 opp2 statsA2 statsB2 statsC2 ,etc...
4 team3 game3 date3 opp3 statsA3 statsB3 statsC3 ,etc...
5 team4 game4 date4 opp4 statsA4 statsB4 statsC4 ,etc...
6 team5 game5 date5 opp5 statsA5 statsB5 statsC5 ,etc...
I've been trying to get the INDEX/MATCH formula I typically use (below) a little more sophisticated to avoid some errors I've been having in data processing. I'm trying to pull the TeamT name from Table 1 and populate the stats rows in Table 2, columns E and beyond. I do this based on a
match of Names between Table1 column D and Table 2 row 1
Dates in Table 1 being <= Dates in Table 2 column C
with the following formula
my current formula =INDEX(Table1!$A:$E,MATCH(1,(Table1!$D:$D=Table2!E$1)*(Table1!$A:$A<=Table2!$C2),0),5)
As you can probably see, if there are multiple dates in Table 1 that are less than C2, I only get the first one. What I'd really like is the maximum (newest one). I've been playing with MAX/IF statements and INDEX/MATCH/IF statements but can't get the proper result. Some examples of those failed tries are below
example 1
=MAX(IF(Table1!$D:$D=Table2!E$1,IF(Table1!$A:$A<=Table2!$C2,Table1!$E:$E)))
example 2
=INDEX(Table1!$E:$E,MATCH(MAX(IF(Table1!$D:$D=Table2!E$1,Table1!$A:$A<=Table2!$C2)),IF(Table1!$D:$D=Table2!E$1,Table1!$A:$A<=Table2!$C2),0))
Any help would be appreciated. I've tried many solutions I've found, but I'm still pulling my hair out on this one.
I also have a second variation of formula where I match dates based on Dates in Table 1 being >= Dates in Table 2 column C. In that case I want the minimum match (the oldest date). I'm assuming I'd simply use MIN instead of MAX for this?
If I understand you correctly, here I have the answer for your first question.
To make the sample easier, I put everything in one sheet. You can copy to the new sheet once you are happy with the result. That way you will have the working formula.
The array formula (click Ctrl + Shift + Enter together) I used from cell K2 is:
=IFERROR(INDEX($E$2:$E$11,MATCH(MAX(IF(--($D$2:$D$11=K$1)*--($A$2:$A$11<$I2)*$A$2:$A$11,$A$2:$A$11)),IF(--($D$2:$D$11=K$1)*--($A$2:$A$11<$I2)*$A$2:$A$11,$A$2:$A$11),0)),"")
You can drag this to the fields you need. Please note this to find the most current date. Because I am not 100% sure this is what you are looking for. Therefore, in my example from cell O2, I managed to find the latest row and the formula (regular formula) is:
=IFERROR(INDEX($E$2:$E$11,LOOKUP(2,1/(--($D$2:$D$11=O$1)*--($A$2:$A$11<$I2)),(ROW($E$2:$E$11)-ROW(O$1)))),"")
For the 2nd question, I will leave it to you to find out from these two and that should do the trick.
I worked this out myself with MAXIFS to find the max date and a multi-criteria VLOOKUP function
this finds the max date less than a current row based on a name match
=VLOOKUP(MAXIFS(Table1!$A:$A,Table1!$D:$D,E$1,Table1!$A:$A,"<="&$C2)&E$1,CHOOSE({1,2},Table1!$A:$A&Table1!$D:$D,Table1!$E:$E),2,0)
the solution to a min date greater than the current row based on a name match is
=VLOOKUP(MINIFS(Table1!$A:$A,Table1!$D:$D,E$1,Table1!$A:$A,">="&$C2)&E$1,CHOOSE({1,2},Table1!$A:$A&Table1!$D:$D,Table1!$B:$B),2,0)

Selecting a row in excel based on specific values in 2 columns,

Data roughly in the format
A B C
ID1 ID2 0.5
ID1 ID3 0.7
ID2 ID3 0.9
I want to create a correlation matrix (column C being the correlation between the IDs in A and B). It can definitely be done with a pivot table, though I have to use sum which could be risky if a duplicate existed since an error might not be apparent. Output format would be:
ID1 ID2 ID3
ID1 1 .5 .7
ID2 .5 1 .9
ID3 .7 .9 1
(the '1' is easily done with an =IF(B$2=$A3,1,0) and replacing 0 with the formula to find the correlation)
I basically want a match (col a= ID1 && col b = ID2). I suspect it could be done by concatenation, but I am not sure that is a great solution? Match/Vlookup etc only return the first match [in that column], which is no good to me. Ode to a 'where' clause I guess?
My searches did not reveal any usuable help, I have already calculated the correlation and am putting it into excel from SQL. So yeah, any ideas would be super, a pivot table being a last resort.
Thanks.
Assuming your source data range is on Sheet1, from A1 to C3 and your results range is on Sheet2, from A1 to D4.
You can put this formula on B2:
=SUMPRODUCT((Sheet1!$A$1:$A$3=Sheet2!B$1)*(Sheet1!$B$1:$B$3=Sheet2!$A2)*Sheet1!$C$1:$C$3)
and then, drag and drop this formula on the whole range.
Why don't you create a third column that combines the values from columns A and B using =A1&B1 and then do vlookup on that value:
A B C D
ID1 ID2 ID1ID2 0.5
ID1 ID3 ID1ID3 0.7
ID2 ID3 ID2ID3 0.9

Resources