Conditional formatting on the first x number of rows, regardless of filter or sort, in Excel - excel

I'm trying to find a way to easily identify the first ten rows in a table column, no matter how it's been sorted/filtered. Is there a way to use conditional formatting to highlight these cells?
Examples of desired results...
Sample data:
product price units code
Item02 15.97 2191 7UQC
Item05 12.95 1523 TAAI
Item13 9.49 1410 LV9E
Item01 5.69 591 6DOY
Item04 15.97 554 ZCN2
Item08 10.68 451 2GN0
Item03 13.95 411 FP6A
Item07 25.45 174 PEWK
Item09 14.99 157 B5S4
Item06 18 152 XJ4G
Item10 11.45 148 BY8M
Item11 16.99 66 86C2
Item12 24.5 17 X31K
Item14 24.95 14 QJEI
When sorting by price the first 10 products highlighted differ from those in the next example.
The first 10 visible products are highlighted after filtering out Item12, Item05, and Item08.
Choosing to sort by units automatically highlights a different set of products.

Use this formula in the Conditional Formatting:
=SUBTOTAL(3,$A$2:$A2)<11
Make sure it applies to the entire dataset.
The formula returns the row number relative to the visible row number. Thus as a row is hidden the row beneath the hidden returns one greater than it would.
To see how it works place SUBTOTAL(3,$A$2:$A2) in an empty column. Then filter the table and watch as the numbers change.
The 3 refers to the COUNTA() function, which will count any non-empty cell.
Subtotal is designed to work with data that gets filtered to return only the visible data.
So the Formula will only count the visible cells that are not empty.

In the conditional formatting dialog, choose New rule -> Use a formula.... Enter =row()<=10.

Related

How to return the last n number of values corresponding to a specific category?

I have the following sample data.
Date Category Price Quantity
02-01-2019 BASE_Y-20 279 1
02-01-2019 BASE_Y-21 271.25 0
03-01-2019 BASE_Y-20 276.5 2
03-01-2019 BASE_Y-21 266.5 0
04-01-2019 BASE_Y-20 272.88 14
04-01-2019 BASE_Y-21 266.5 1
07-01-2019 BASE_Y-20 270.48 29
07-01-2019 BASE_Y-21 262.75 0
08-01-2019 BASE_Y-20 270 4
08-01-2019 BASE_Y-21 264 0
09-01-2019 BASE_Y-20 270.06 31
09-01-2019 BASE_Y-21 262.85 0
What is a dynamic formula that I can use to return the last 5 prices corresponding to category BASE_Y-20 ? The formula must return whatsoever prices are available, if 5 values are not present, which is the challenging part. (Eg: For the given data, 270.06, 270, 270.48, 272.88 and 276.5 must be returned. If we only had 1st row, it must return 279)
I have tried sumproduct. That of course gives the corresponding prices. Offset can be availed to get last 5 data. But no way for getting last 5 prices corresponding to a specific category that is dynamic.
You can try:
Formula in F3:
=TAKE(SORT(FILTER(A:C,B:B=F1),1),-F2,-1)
Few notes:
The latest price will be at the bottom;
If your data is always sorted to begin with, just ditch the nested SORT() and use =TAKE(FILTER(A:C,B:B=F1),-F2,-1);
If no value is present at all, nest the formula in an =IFERROR(<Formula>,"") to return any value you'd like to display in such event.
Last Matches From Bottom to Top
EDIT
With great help from P.b, the formula got reduced to the following:
=LET(cData,B2:B13,rData,C2:C13,cStr,G1,rCount,G2,
rFiltered,IFERROR(TAKE(TAKE(FILTER(HSTACK(cData,rData),cData=cStr),,-1),-rCount),""),
Result,SORTBY(rFiltered,SEQUENCE(ROWS(rFiltered)),-1),Result)
Screenshot Formulas
J2 =HSTACK(B2:B13,C2:C13)
L2 =FILTER(J2#,B2:B13=G1)
N2 =TAKE(L2#,,-1)
O2 =TAKE(N2#,-G2)
P2 =ROWS(O2#)
Q2 =SEQUENCE(P2)
R2 =SORTBY(O2#,Q2#,-1)
Issues in the Initial Post
I'm not sure what drove me to the decision that the data is A3:D13 when it is obviously B3:B13 and C3:C13.
TAKE will work if there are fewer rows/columns than asked for i.e. if you need five rows and there are only two, two will be returned.
Instead of using ROWS with the SEQUENCE function and then using it with INDEX, it is simpler to use SORTBY to sort by the sequence, in this particular case descending (-1).
Initial Post (Bad)
LET
=LET(Data,A2:D13,cCol,2,cStr,G1,rCol,3,rCount,G2,
cData,INDEX(Data,,cCol),rData,INDEX(Data,,rCol),Both,HSTACK(cData,rData),
bFiltered,FILTER(Both,cData=cStr),rFiltered,TAKE(bFiltered,,-1),rRows,ROWS(rFiltered),
fRows,IF(rRows>rCount,rCount,rRows),rSequence,SEQUENCE(fRows,,rRows,-1),
Result,INDEX(rFiltered,rSequence),Result)
Screenshot Formulas
J3 =INDEX(A2:D13,,2)
K3 =INDEX(A2:D13,,3)
L3 =HSTACK(J3#,K3#)
N3 =FILTER(L3#,J3#=G1)
P3 =TAKE(N3#,,-1)
Q3 =ROWS(P3#)
R3 =IF(Q3>G2,G2,Q3)
S3 =SEQUENCE(R3,,Q3,-1)
T3 =INDEX(P3#,S3#)

Excel - Find row with conditional statement in XLOOKUP

I'm trying to use XLOOKUP to find a value based on user inputs.
The table looks like this:
Type Start End 33 36 42 48
---------------------------------------
4002 1 7 1.17 1.34 1.5 1.84
4002 8 12 1.84 1.67 2.1 3.45
User selects type, number (can be between start and end), and 33-48
I can nest an XLOOKUP to specify the 3 criteria
=XLOOKUP(*type* & *number* , *typeRange* & *numberRange* ,XLOOKUP(*33-48* , *33-48Range* , *ResultRange* ))
And I can find if a value is between the columns
=IF(AND(*number*>=*Start*,*number*<=*End*),TRUE,FALSE)
Can I combine the two? The data is redundant for numbers 1-7, and I would like to keep the table small.
You sort-of can combine them. I have added a couple of extra rows to the table to see what would happen if you had different Type values as well as number values. The problem then is that if you used approximate match and put in a number like thirteen which is out of range, you might end up getting the next row of the table which would be incorrect. One way round it would be to use the options in Xlookup to search for next-smaller-item in the Start column and next-larger-item in the End column and see if the results match:
=IF(XLOOKUP(I2&TEXT(J2,"00"),A2:A7&TEXT(B2:B7,"00"),XLOOKUP(K2,D1:G1,D2:G7),,-1)=XLOOKUP(I2&TEXT(J2,"00"),A2:A7&TEXT(C2:C7,"00"),
XLOOKUP(K2,D1:G1,D2:G7),,1),XLOOKUP(I2&TEXT(J2,"00"),A2:A7&TEXT(C2:C7,"00"),XLOOKUP(K2,D1:G1,D2:G7),,1),"Error")
If you have some checks in place which make it impossible for number to be out of range, then you can simplify the formula:
=XLOOKUP(I2&TEXT(J2,"00"),A2:A7&TEXT(B2:B7,"00"),XLOOKUP(K2,D1:G1,D2:G7),,-1)
or
=XLOOKUP(I2&TEXT(J2,"00"),A2:A7&TEXT(C2:C7,"00"),XLOOKUP(K2,D1:G1,D2:G7),,1)

Create a formula that returns a minimum date from a range based on cell values in another column

I am looking for a formula that will return the earliest date from a column, based on the contents of values in other cells. (Actually I want a Min and Max date, but am assuming the Max will be identical to any Min solution )I know I can return the date I want just by using MIN and specifying the range of cells I want, but I ideally want the formula to be dynamic. I have looked around and believe I possibly need to use a combination of index and match, but cant find any examples that use Min and Max. I have considered using dynamic named ranges to define my task groups, but that would mean having to define a static number of task groups, and there could be many task groups.
The sheet below shos some sample date on the left of the workbook, with the summary data on the right. The "hidden worker column" was an idea I had that I though might make the solution easier. So I want the summary data on the right to use either column A, or column B if its easier, to display the min and max dates based on the section number in column F - Is this possible without VBA?
#mthierer's link is good. If you wanted to remove the need to add a "helper column", you could try (data in A1:C10; summary table in E1:G2):
{=MIN(IF(ROUNDDOWN($A$1:$A$10, 0)=$E1, $B$1:$B$10))} (or {=MAX(...)} with $C$1:$C$10)
Note that you have to enter the formula as an array formula with CtrlShiftEnter.
Data (A1:C10):
1 23 57
1.1 42 91
1.2 35 100
1.3 39 80
1.4 28 51
1.5 30 96
2 33 52
2.1 11 73
2.2 48 80
2.3 16 59
Summary Results (E1:G2):
1 23 100
2 11 80

In excel, I need to find the maximum date based on the employee number

I have tried to use the following formula when trying to find the max date of these columns based on the employee number in my hundreds of thousands lines of data. The formula bar gives me 'yes' when it is the max, however in my cell it says 'no'. I cannot figure out what the issue is. Thanks for the help.
Tamara
Excel Max date formula Image
Formula used: =IF(AQ2=MAX(IF($C:$C=C2,$AQ:$AQ)),"YES","NO")
A B Employee Number Max?
11-Mar-13 12-Mar-13 199 NO
24-Mar-13 26-Mar-13 199 NO
1-Aug-13 6-Aug-13 199 NO
22-Dec-13 27-Dec-13 199 NO
15-Apr-13 17-Apr-13 206 NO
18-Apr-13 18-Apr-13 206 NO
8-Aug-13 10-Aug-13 206 NO
17-Oct-13 18-Oct-13 206 NO
25-Dec-13 20-Feb-14 206 YES
8-May-13 8-May-13 214 NO
You can also accomplish this without an array is all of the dates for a specific employee ID are unique--that is, you won't have two of the same date. In this case, the following formula will check that (a) the number of dates with employee ID is equal to (b) the number of dates with employee ID that are less than or equal to the current employee ID. This will only be true for the "max" date for said employee id:
=IF(COUNTIFS($C:$C,C2)=COUNTIFS($C:$C,C2,$A:$A,"<="&A2),"Yes","No")
If I understand your question correctly, you want to find the set of dates with the largest time span in between said dates. If this is the case, then I would recommend using two seperate fucntions, the =DAYS360 function and the =MAX function.
I have re-created your sheet and it will end up looking similar to this:
Here is the same picture of the same sheet with functions revealed, so that you can see how the functions are used:
The =DAYS360 function takes two inputs, and return the number of days in between two dates. The max function simply finds the largest number in a range. Please let me know if this helped.
EDIT: Also, if you want to see the actual word Max next to the largest date range, you can nest the Max fucntion from my column E within an If function, like this:
=IF(MAX(D:D)=D2,"Max","")
If I understand you correctly, do you want "YES" to appear for each employee's max date range? Assuming column AQ contains the spans between dates in columns A and B (i.e. =B2-A2 copied down), your formula should work.
This only works as an array formula, so make sure you press CTRL+SHIFT+ENTER when entering the formula, then copy it down to all cells in the same column.
=IF(AQ2=MAX(IF($C:$C=C2,$AQ:$AQ)),"YES","NO"), entered in D2 using CTRL+SHIFT+ENTERand copied down produces the following:
A B C D ... AQ
11-Mar-13 12-Mar-13 199 NO 1
24-Mar-13 26-Mar-13 199 NO 2
1-Aug-13 6-Aug-13 199 YES 5
22-Dec-13 27-Dec-13 199 YES 5
15-Apr-13 17-Apr-13 206 NO 2
18-Apr-13 18-Apr-13 206 NO 0
8-Aug-13 10-Aug-13 206 NO 2
17-Oct-13 18-Oct-13 206 NO 1
25-Dec-13 20-Feb-14 206 YES 57
8-May-13 8-May-13 214 YES 0
If you are simply looking for the greatest date range, the formula =IF(E2=MAX($E:$E),"YES","NO") entered in D2 and copied down will do the trick.

Return Kth largest Value of range that is determined by an Index & Match lookup

My question is similar to one asked here, but I am having trouble making this work for my situation given my data. I have a data set that uses seeded numbers in row 1 that I use to index match columns. This is because there are drop-down menus that change the match column based on user selection. So the the columns cannot be directly referenced. My data very roughly looks like this:
45 46 50 28
Route
CCS 500 325 40 200
CCS 370 100 380 10
RCS 90 825 50 999
CCS 100 50 32 358
So when my user makes a selection, the number in AE2 changes to reflect the column seed I want (in example, either 45, 46, 50, or 28). I want to be able to return the Kth largest number in that column that is also "CCS". So lets say the user chooses 46 and I want the 2nd largest number that has "CCS" in Route. So the formula searches row 1 for "46", then once it finds the column with it, it looks down that column for the 2nd largest CCS value -- which is 100. I have tried to modify the formula suggested in the other question, (below) but that just seems to stop at the first observation, and I need it to search all of the observations.
LARGE(IF( 'Program Data'!O:O="CCS", INDEX('Program Data'!$A:$GB,0,(MATCH($AE$2,'Program Data'!$1:$1,0)))),1)
Any tips as to what I'm doing wrong?
Your formula works for me....but it's an "array formula" so you need to confirm with CTRL+SHIFT+ENTER so that curly braces like { and } appear around the formula

Resources