Excel - Conditional Format Top Value IF Both Cells Are Not Blank - excel

I have a sheet that shows the daily sales on one row and if that month is the current month will show the last years sales on the row below that - else it will be "".
I then want to format the values to highlight the top 1 value, but only if both cells are not blank (or "").
Example (snippets):
A B C D
====================================================
1 = Jan | 1-Jan-18 | 2-Jan-18 | 3-Jan-18
2 = 2018 | Mon | Tue | Wed
3 = MI | 0 | 4 | 4
4 = SC | 0 | 0 | 0
5 = Subtotal | 0 | 4 | 4
6 = DS | 0 | 0 | 0
7 = Total | 0 | 4 | 4
8 = Daily Sales | $- | $1,763.72 | $1,763.72
9 = "" | "" | "" | ""
. . .
51 = Jun | 1-Jun-17 | 2-Jun-17 | 3-Jun-17
52 = 2017 | Thu | Fri | Sat
53 = MI | 29 | 33 | 33
54 = SC | 40 | 34 | 38
55 = Subtotal | 69 | 67 | 71
56 = DS | 37 | 35 | 39
57 = Total | 106 | 102 | 110
58 = Daily Sales | $46,738.63 | $44,974.91 | $48,502.35
59 = Last Year | $34,899.21 | $34,557.87 | $36,945.18
Please note the "" aren't actually there. I'm just showing the values are blank.
So cells B8:D9 should not be highlighted, as row 9 is blank. Cells B58:D58 should be highlighted, as both row 58 and row 59 are not blank and row 58 is the higher value.
How do I go about doing this? I was trying just a "Top 1" value, but it highlights the values in row 8 which just looks weird as there is no values in row 9 to compare with.
Solution should be fully automatic. I don't want to manually have to update conditional formats, cells, etc.

Select cell B8 and create a new conditional formatting rule using a formula. Put in this formula:
=AND(COUNT(B8:B9)=2,B8=MAX(B8:B9))
Select cell B9 and create a new conditional formatting rule with this formula:
=AND(COUNT(B8:B9)=2,B9=MAX(B8:B9))
Set the desired formats for both rules. Apply the rules to more cells or just copy the two cells and use Paste Special > Formats to apply to any other pair of cells that are one below the other.

I got it to work using =AND(B9<>"",B8>B9) for cells =$B$8:$B$9 (example range) and just copied that for other cells (eg. =AND(C9<>"",C8>C9) for cells =$C$8:$C$9.

Related

copying multiple cell contents into a single cell

Is there a formula that can do the following:
Copy all the contents on column A, rows 1 to 4, into a new cell, and separate the contents using a new line.
Example input:
| A |
Row 1 | Alpha Beta Omega |
Row 2 | |
Row 3 | 21321 Cri Je |
Row 4 | Cappa NF B |
Example output:
Row 5 | Alpha Beta Omega
21321 Cri Je
Cappa NF B |
For Google sheets,
=JOIN(CHAR(10),FILTER(A1:A4,A1:A4<>""))
For Google sheets as well as Excel 2016 (w/Office365),
=TEXTJOIN(CHAR(10),1,A1:A4)

Excel: Remove Duplicates based on time condition

I'm looking to remove duplicates from a 250,000 row excel sheet based on a 3 month rolling time condition.
We have a lot of usersIDs and the dates which they visited but a lot of these visits are very far apart (sometimes over a year) and a lot of them are within the same day/couple day period.
The best way to explain what I want to do is with an example. So if they first visited on 1st Jan, 1st Jan, 3rd Jan, 8th Feb, 4th June, 5th June, 1st Dec, 1st Dec, 2nd Dec, I would want to grab that first date of 1st Jan, 4th June and 1st Dec.
If they visited 1st Jan, 1st Jan, 3rd Jan, 8th Feb, 9th Apr then 1st August, 1st Sept, I would want 1st Jan and 8th August.
So we want to grab the first date, then see how often they visit within 3 months of each visit and if they leave for more than a 3 month period, grab the first date that they return. Sometimes they come back 4 or 5 times after 3 months and the data can span several years.
Is there a way for me to achieve this? It would be great to get some help as this is driving me mad.
Cheers
If the UserID is in column A and the VisitDate is in B with the headings in row 1 and then a blank row in 2 and the data starting in row 3 then try this (explanation below):
Array Formula version:
sort the rows ascending by VisitDate
in B2 put 1/1/1900 so it won't match anything (but it has to be a date)
in C3 put this array formula (press control-shift-enter instead of just enter):
=SUM((B$2:B2<DATE(YEAR(B3),MONTH(B3)-3,DAY(B3)))*(A$2:A2=A3))=SUM((A$2:A2=A3)*1)
Copy the formula in C3 down to every row of data
Filter on Unique = TRUE
if you want to resort you will need to copy and paste back column C by values
New non-array formula version:
sort the rows ascending by VisitDate
in B2 put 1/1/1900 so it won't match anything (but it has to be a date)
in C3 put this normal formula (just press enter):
=COUNTIFS(B$2:B2,"<"&DATE(YEAR(B3),MONTH(B3)-3,DAY(B3)),A$2:A2,A3)=COUNTIF(A$2:A2,A3)
Copy the formula in C3 down to every row of data
Filter on Unique = TRUE
if you want to resort you will need to copy and paste back column C by values
This produces the following with my sample data (array formulas may take a very long time to calculate for lots of rows):
| A | B | C
---+--------+------------+--------
1 | UserID | VisitDate | Unique
2 | | 1/01/1900 |
3 | a | 1/01/2017 | TRUE
4 | a | 1/01/2017 | FALSE
5 | b | 2/01/2017 | TRUE
6 | b | 2/01/2017 | FALSE
7 | a | 3/01/2017 | FALSE
8 | c | 3/01/2017 | TRUE
9 | c | 3/01/2017 | FALSE
10 | b | 4/01/2017 | FALSE
11 | c | 5/01/2017 | FALSE
12 | a | 8/02/2017 | FALSE
13 | b | 9/02/2017 | FALSE
14 | c | 10/02/2017 | FALSE
15 | a | 4/06/2017 | TRUE
16 | a | 5/06/2017 | FALSE
17 | b | 5/06/2017 | TRUE
18 | b | 6/06/2017 | FALSE
19 | c | 6/06/2017 | TRUE
20 | c | 7/06/2017 | FALSE
21 | a | 1/12/2017 | TRUE
22 | a | 1/12/2017 | FALSE
23 | a | 2/12/2017 | FALSE
24 | b | 2/12/2017 | TRUE
25 | b | 2/12/2017 | FALSE
26 | b | 3/12/2017 | FALSE
27 | c | 3/12/2017 | TRUE
28 | c | 3/12/2017 | FALSE
29 | c | 4/12/2017 | FALSE
Because the formula compares the current row with all the rows above looking for rows with dates in the past the data needs to be sorted with the oldest dates first.
How the array formula works:
=SUM((B$2:B2<DATE(YEAR(B3),MONTH(B3)-3,DAY(B3)))*(A$2:A2=A3))=SUM((A$2:A2=A3)*1)
DATE(YEAR(B3),MONTH(B3)-3,DAY(B3)) is 3 months ago (even if it is 92 days)
(B$2:B2<DATE(YEAR(B3),MONTH(B3)-3,DAY(B3))) is an array of TRUE/FALSE values which has a TRUE for every row above that is older than 3 months ago
(A$2:A2=A3) is an array of TRUE/FALSE values which has a TRUE for every row above that matches the user ID
(B$2:B2<DATE(YEAR(B3),MONTH(B3)-3,DAY(B3)))*(A$2:A2=A3) does an AND of the arrays so 1 is returned (TRUE*TRUE=1) for each row above that has the same name and a date that is older than 3 months ago
SUM((B$2:B2<DATE(YEAR(B3),MONTH(B3)-3,DAY(B3)))*(A$2:A2=A3)) adds all the TRUE rows above that have the same name and a date that is older than 3 months ago
SUM((A$2:A2=A3)*1) adds the number of rows above that have the same name (TRUE*1=1)
=SUM((B$2:B2<DATE(YEAR(B3),MONTH(B3)-3,DAY(B3)))*(A$2:A2=A3))=SUM((A$2:A2=A3)*1) compares the two sums and returns TRUE if all the rows above that have the same name are all older than 3 months ago
Methodology:
I originally just played with a column of dates - no userID. I wanted to find a way to know if the date on a particular was more than 3 months after all the dates before it (I implicitly assumed that the dates were sorted). I reasoned that if a count of the dates before the current row matched a count of the dates before the current row that were older than 3 months in the past then I would have the answer I wanted. So I originally put this formula in C3 and copied it down:
=COUNTIF(B$2:B2,"<"&(B3-90))=COUNTA(B$2:B2)
Then change it to 3 months instead of 90 days:
=COUNTIF(B$2:B2,"<"&DATE(YEAR(B3),MONTH(B3)-3,DAY(B3)))=COUNTA(B$2:B2)
And then to add the userID we need a way to compare multiple criteria - this is where COUNTIFS comes in (if you have Excel 2007 or better):
=COUNTIFS(B$2:B2,"<"&DATE(YEAR(B3),MONTH(B3)-3,DAY(B3)),A$2:A2,A3)=COUNTIF(A$2:A2,A3)
And then I converted it to this array formula:
=SUM((B$2:B2<DATE(YEAR(B3),MONTH(B3)-3,DAY(B3)))*(A$2:A2=A3))=SUM((A$2:A2=A3)*1)
In retrospect I don't know if giving the array formula was a good idea or not: I don't know whether the array formula would be better/faster than COUNTIFS or not. So use whichever you prefer.

Excel Ranking tie assistance

Can anyone help me to do the following in relation to ties when using the Excel Rank function?
Col A contains scores and B contains the rank. I am quite happy with this except that I would like to show an '=' next to the ranking where it is a tie:
Score Rank
66 3
64 4=
63 6
68 2
64 4=
81 1
etc
Many thanks.
You can combine your RANK with COUNITF. Place the following into cell B3 as per the example
=RANK(A3,$A$3:$A$7)&IF(COUNTIF($A$3:$A$7,A3)>1,"=","")
Note, if you are using Excel 2013 or 2016, it would be a good idea to replace RANK with RANK.EQ
This can be done in another column next to the column where you have ranked it.
Step 1: Rank the numbers in a simple manner using RANK.EQ
Output:
(A)|(B)
66 | 3
64 | 4
63 | 6
68 | 2
64 | 4
81 | 1
Step 2: In another column use the code IF(COUNTIF(A:A,A1)>1,CONCATENATE(B1,"="), B1)
Output:
(A)|(B)|(C)
66 | 3 | 3
64 | 4 | 4=
63 | 6 | 6
68 | 2 | 2
64 | 4 | 4=
81 | 1 | 1
You can paste the values and remove the columns as required.
Hope it helps. :)

Increment a number inside excel formula sidewise

I have following numbers in Column D1 to D21
1 | 4 | 51 | 4 | 57 | 6 | 16 | 11 | 41 | 3 | 26 | 3 | 27 | 5 | 3 | 5 | 8 | 6 | 22 | 6 | 23
I want to write a formula which will produce an output like this:
6:23 6:22 5:8 5:3 3:27 3:26 11:41 6:16 4:47 4:51 1
I have put the following formula on Column P1 and tried dragging on the left side but it is showing the same value in all rows as the value of 1 & 2 is not changing to 3 & 4:
This is what i want:
OFFSET($D$1,1,0)&":"&OFFSET($D$1,2,0)
OFFSET($D$1,3,0)&":"&OFFSET($D$1,4,0)
OFFSET($D$1,5,0)&":"&OFFSET($D$1,6,0)
The middle value in the above formula should change.
I've tested with a smaller range of values and the following should work for you. You'll need to replace $A$1:$I$1 with your range.
=IFERROR(OFFSET($A$1,0,COUNT($A$1:$I$1)-(COLUMN()*2))&":"&OFFSET($A$1,0,COUNT($A$1:$I$1)-((COLUMN()*2)-1)),IF((COUNT($A$1:$I$1)+1)=(COLUMN()*2),$A$1,""))
Also tested with your full range $A$1:$U$1:
=IFERROR(OFFSET($A$1,0,COUNT($A$1:$U$1)-(COLUMN()*2))&":"&OFFSET($A$1,0,COUNT($A$1:$U$1)-((COLUMN()*2)-1)),IF((COUNT($A$1:$U$1)+1)=(COLUMN()*2),$A$1,""))

Aligning cells into the same column based on similar values

I recently pulled some data into excel and some of the cells ended up like :
{paypal:34, giftcard: 34, authorizenet: 44} (for payment methods)
I managed to divide them up into separate columns as such:
paypal: 34 | giftcard: 34 | authorizenet: 44 |
but not all lines have the same categories. Some have less payment methods while others have more.
So I basically have a large table of
paypal: 34 | giftcard: 34 | authorizenet: 44 |
authorizenet: 34 |
giftcard: 34 | authorizenet: 44 |
paypal: 34 | check: 3 |
Is there a way to align the cells in each row where if they contain "paypay", they align into a single column and so on? I was thinking about sorting but they won't exactly line up.
paypal: 34 | giftcard: 04 | authorizenet: 34 |
paypal: 31 | giftcard: 24 | authorizenet: 45 |
paypal: 74 | giftcard: 31 | authorizenet: 74 |
Thanks!
You should start by using the 'Text to Columns' functions in excel.
First, select all your data then go to: Date > Data Tools > Text to Columns.
Next, select 'Delimited' > Next >
Next, check only 'Comma' > Next >
Finally, Click 'Finish'
Now you have all of the different payment types in separate columns/ cells and need to 'align' all your 'Paypal' in the same column and 'Authorize.Net' in the same column and so on. Use the following formula to get this 'alignment' part done:
=IF(LEFT(C7,6)="Paypal",C7,IF(LEFT(D7,6)="Paypal",D7,IF(LEFT(E7,6)="Paypal",E7,"")))
=IF(LEFT(C7,6)="Giftca",C7,IF(LEFT(D7,6)="Giftca",D7,IF(LEFT(E7,6)="Giftca",E7,"")))
=IF(LEFT(C7,6)="Author",C7,IF(LEFT(D7,6)="Author",D7,IF(LEFT(E7,6)="Author",E7,"")))
You will need to edit the directly reference cells that I show above to fit your own worksheet needs. My parsed (after splitting my data from delimiters) data was in columns C, D, and E. Therefore, I used C7, D7, and E7 to use the 'left' formula on. These formulas on my worksheet were in cells G7, H7, and I7. Give is a try and let me know.
Tip: on the 'Left' formula, make sure the text string is exact (capitals, spaces, etc).
Good luck!

Resources