Conditionally formatting if Top 10 in two categories? - excel

I have two columns of data. I want to find which cities are in the top 10 in both columns (format IF in top10_1 AND top10_2), and this is the formula I am trying to use:
=AND(LARGE($B$2:$B$330,10),(LARGE($C$2:$C$330,10))
Any suggestions on what I can do to make it work? I included some sample data if it helps.
CityState Climate Housing
Stamford, CT 2.959 -4.234
Norwalk, CT 2.959 -4.118
San Diego, CA 2.955 -4.160
Honolulu, HI 2.949 -4.146
San Jose, CA 2.946 -4.205

LARGE returns the nth highest value in a set, so your condition would be something like:
=AND($B2 >= LARGE($B$2:$B$330,10),$C2 >= LARGE($C$2:$C$330,10))
Note the relative row reference in each condition so that the conditional formatting applies to each row individually.

Related

I need to pull a complete row from one excel sheet to another escel sheet, based on a cell value

I have 2 Excel worksheets. In the first I have a table that has a column named "Sales Order" and "SO Item" of each row (product) plus some other columns. In this table I concatenate "Sales Order" and "SO Item" so that I have Sales Order parent (xxxxxxx00) and also Sales Order childs (xxxxxxx01, xxxxxxx02,...,xxxxxxx09). However, in the second worksheet I also have the "concatenation" column but only contains Sales Order parents. How can I pull the whole rows containing the childs of each parent from worksheet 1 to worksheet 2?
I've tried to do it using VLOOKUP but this only returns a single child value (xxxxxxx001) and also its not returning the whole row where this code is located
Table 1 is:
Sales Order
SO Item
Concatenation
Material Description
Feas Plan Date
2503319449
100
2503319449100
SYS-7210 SAS-Mxp
Bundle Header
2503319449
101
2503319449101
PS-7210 SAS-T/Mxp
1/31/2023
2503319449
102
2503319449102
SYS-7210 SAS-Mxp2VDC
Global Allocation
2503319449
200
2503319449200
OS-7210 SAS-Mxp
1/31/2023
Table 2 is:
Sales Order
SO Item
Concatenation
Material Description
Feas Plan Date
2503319449
100
2503319449100
SYS-7210 SAS-Mxp
Bundle Header
2503319449
200
2503319449200
OS-7210 SAS-Mxp
1/31/2023
I want Table 2 to extract the missing "Concatenation" items from Table 1.
It is not clear from the question, how to present the output. I assume Table2 is your lookup table. Based on the input data, you need to return the entire Table1, I assume your Table1 has more data in your real case, and you want to extract just the information based on the lookup table. In the way you construct the concatenation, for the lookup it is only necessary the SO Item column values. Put on G2 the following formula:
=LET(tbA, A3:E4, tbB, A9:E12, soA, 1*INDEX(tbA,,2), soB, 1*INDEX(tbB,,2),
DROP(REDUCE("", soA, LAMBDA(ac,x, LET(f,
FILTER(tbB, (soB >= x) * (soB < x+100),""), IF(#f="", ac, VSTACK(ac,f))))),1))
Here is the output:
The condition:
IF(#f="", ac, VSTACK(ac,f))
It is just to prevent empty result from the FILTER output (f), it is not really necessary if you want to include the parent (condition: soB >= x as it is in the formula), but if you want to exclude it (soB > x) then you need it. Check my answer to the question: how to transform a table in Excel from vertical to horizontal but with different length on how to use DROP/REDUCE/VSTACK pattern. I convert to numeric values (multiplying INDEX by 1) the value of SO Item column, in case the input data is in text format, otherwise it is not necesary.

How to get min() max() sequentially from a single column?

Hi Stackoverflow Community,
This is my first post, apologies ahead if I haven't structured my question better, I'll try to improve on it later on.
I have a 2 excel columns with street address numbers and street address, none of which are unique hence using vlookup/index match is tricky.
I am trying to populate another column with the minimum and maximum value of the street address numbers using TEXTJOIN and it works, however I need the min/max for each specific street address group, there are close to 1 million lines of data.
For example, min=1, max=13, on florence st, min=3, max=53, on gibson st
Is such a formula helpful for you:
=MINIFS(B$2:B$10,A$2:A$10,"Ramsay street")
As you see, I take the minimum value of the "B" column, based on a criterion on the "A" column.
Hereby a screenshot of an example:
If you are on Excel 365 - current channel you can use this formula:
=LET(streetnamesUnique,UNIQUE(data[StreetName]),
minNumber,BYROW(streetnamesUnique,LAMBDA(s, MINIFS(data[Number],data[StreetName],s))),
maxNumber,BYROW(streetnamesUnique,LAMBDA(s, MAXIFS(data[Number],data[StreetName],s))),
HSTACK(streetnamesUnique,minNumber,maxNumber))
If on Excel 365 semi annual channel:
=LET(streetnamesUnique,UNIQUE(data[StreetName]),
minNumber,BYROW(streetnamesUnique,LAMBDA(s, MINIFS(data[Number],data[StreetName],s))),
maxNumber,BYROW(streetnamesUnique,LAMBDA(s, MAXIFS(data[Number],data[StreetName],s))),
MAKEARRAY(ROWS(streetnamesUnique),3,LAMBDA(r,c,
IF(c=1,INDEX(streetnamesUnique,r),
IF(c=2,INDEX(minNumber,r),
INDEX(maxNumber,r))))))
Both formulas first retrieve the unique streetnames - then retrieves, per each streetname min and max number.
In the end the new range is built from these values - either by HSTACK or MAKEARRAY.

VLOOKUP MULTIPLE RANGES

Column A and B is a item and country post code. Column B contain two country post code USA and UK. Both country we have dispatched same part. I am trying to create vlookup formula corresponding to the range but its return na. Please help me.
Country code ranges;
USA Angeles10 Angeles20 Angeles30 Angeles40 Angeles50 Angeles60 Angeles70 Angeles80 Angeles90 Angeles100 Angeles110 Angeles120 Angeles130 Angeles140 Angeles150
UK London10 London20 London30 London40 London50 London60 London70 London80 London90 London100 London110 London120 London130 London140 London150
DATA
ITEM POST CODE
4 Angeles10
4 Angeles20
110489 Angeles30
110489 Angeles40
113388 Angeles50
113388 Angeles60
113636 Angeles70
113636 Angeles80
11363613001 Angeles90
11363613001 Angeles100
11363613002 Angeles110
11363613002 Angeles120
11363613003 Angeles130
11363613003 Angeles140
1136362001 Angeles150
4 London10
4 London20
110489 London30
110489 London40
113388 London50
113388 London60
113636 London70
113636 London80
11363613001 London90
11363613001 London100
11363613002 London110
11363613002 London120
11363613003 London130
11363613003 London140
1136362001 London150
DESIRED RESULT
ITEM USA UK
4 Los Angeles10 London10
I put the first data on a sheet named datasheet in starting in A1.
Then use a formula like so in the E3:
=INDEX($B:$B,AGGREGATE(15,6,ROW($B$2:$B$31)/((ISNUMBER(MATCH($B$2:$B$31,INDEX(datasheet!$1:$1048576,MATCH(E$2,datasheet!$A:$A,0),0),0)))*($A$2:$A$31=$D3)),1))
Then copy/drag over and down.
Easiset Answer
If your data isn't changing and you know exactly where Angeles stops and London starts, you can just use a standard VLOOKUP formula. You just give the bottom part of the table to the UK column.
E3: =VLOOKUP(D3,A$3:B$6,2,)
F3: =VLOOKUP(D3,A$7:B$10,2,)
A little more complicated
If you need to be able to add rows or locations, this solution will work better. Add helper columns for each of the locations you need and a helper column which combines the item ID with the location. You can then use VLOOKUP by searching for the combination of item ID and location.
B3: =A3&CONCAT(D3:E3) (can expand past E3 for extra locations)
D3: =IF(ISERR(SEARCH(D$2,$C3)),"",D$2)
E3: =IF(ISERR(SEARCH(E$2,$C3)),"",E$2) (can drag right for each extra location)
H3: =VLOOKUP($G3&H$2,$B$3:$C$10,2,)
I3: =VLOOKUP($G3&I$2,$B$3:$C$10,2,) (can drag right for each extra location)
My favorite Answer
Just use Scott Craner's approach! ☺

Conditional formatting in Excel or SQL Server

I have about 500k records in an Excel sheet. I am tasked to identify sellers who have multiple purchase id and buyer id. For example, seller_id (12525) has three different purchase_id (8569, 8591, 8594) and buyer_id C160511, C160512, C160513).
What is the correct syntax to use in Excel 2013 that can easily identify the records I am interested? I searched the web about the conditional formatting.
location Loc_Id Purchase_id buyer_id Seller_Id Date
CA 49456 8569 C160511 12525 5/3/2016
CA 49456 8569 C160511 12525 5/3/2016
CA 49456 8591 C160512 12525 5/3/2016
CA 49456 8591 C160512 12525 5/3/2016
CA 49456 8594 C160513 12525 5/3/2016
CA 49456 8594 C160513 12525 5/3/2016
TX 37140 8620 C170166 5621 1/24/2017
TX 37140 8621 C170167 5621 1/24/2017
Solution is bit lengthy but easy. I have included an extra condition as seller Id 5623 which does not have multiple buyer and purchase id. This is done to test this solution better. I have only highlighted sellerIds which has multiple Buyer and Purchase Id.
Image of my solution:-
Note:- All the formulas or cell names are according to my solution as shown in the image
Now the solution. I will break it in different parts:-
Step 1:- Add a column say Purchase_Id_cnt and write this formula and drag it down till the end
=IF(SUMPRODUCT(($A$2:$A2=A2)*($C$2:$C2=C2))>1,0,1)
Step2 :- Add a column say Buyer_Id_cnt and write this formula and drag it down till the end
=IF(SUMPRODUCT(($B$2:$B2=B2)*($C$2:$C2=C2))>1,0,1)
Step3 :- Add Pivot table in the same sheet(you can use different sheet also. I used cell F1 in same sheet)
Step4:- Add another column say Header (You can give a better name) and enter this formula corresponding to Pivot table in cell I3 in my case and drag it down till the end
=IF(AND(G3>1,H3>1),1,0)
Step5:- Now Select/Higlight C2 to C11. Then go to conditional formatting. Select 'New Rule'. Then Select 'Use a formula to determine which cells to format'.
Step6:- Enter this formula under 'Format Values where this formula is True'
=IFERROR(VLOOKUP(C2,$F$3:$I$5,4,0),0)=1
Step7:-Don't press 'OK' yet. Click on 'Format'. Go in 'fill' tab. Choose any color you want. I choose yellow and then press 'OK'.
Done!!!
Since you mention SQL Server, I'll answer using that. Honestly, your database is a MUCH better place to be doing this. With excel you would have two problems.
Identify these sellers
Apply conditional formatting based on 1.
And problem 1 is going to be heavy processing for 500k records in excel.
On to SQL Server:
SELECT Seller_ID,
CASE WHEN COUNT(DISTINCT Purchase_ID) > 1 THEN 'X' ELSE NULL END AS multiple_purchases,
CASE WHEN COUNT(DISTINCT Buyer_ID) > 1 THEN 'X' ELSE NULL END AS multiple_buyers
FROM your_table_name
HAVING multiple_purchases = 'X' OR multiple_buyers='X'
GROUP BY Seller_ID;
So here we are just aggregating the records by Seller_ID and then using a CASE statement and aggregation formula COUNT(DISTINCT <field>) to get the number of distinct (unique) purchase_id and buyer_id. The HAVING clause tests to see if either of those tests produced a hit and, if not, it drops the record from the result set.
Use the following formula in Conditional Formatting:
=COUNTIFS($B:$B,$B1,$C:$C,"<>" & $C1)>0

Using tbl.Lookup to match just part of a column value

This question relates to the Schematiq add-in for Microsoft Excel.
Using =tbl.Lookup(table, columnsToSearch, valuesToFind, resultColumn, [defaultValue]) the values in the valuesToFind column have a consistent 3 characters to the left and then varying characters after (e.g. 908-123456 or 908-321654 - i.e. 908 is always consistent)
How can I tell the function to lookup the value based on the first 3 characters only? The expected answer should be the sum of the results of the above, i.e. 500 + 300 = 800
tbl.Lookup() works by looking for an exact match - this helps ensure it's fast but in this case it means you need an extra step to calculate a column of lookup values, something like this:
A2: =tbl.CalculateColumn(A1, "code", "x => LEFT(x, 3)", "startOfCode")
This will give you a new column that you can use for the columnsToSearch argument, however tbl.Lookup() also looks for just one match - it doesn't know how to combine values together if there is more than one matching row in the table, so I think you also need one more step to group your table by the first 3 chars of the code, like this:
A3: =tbl.Group(A2, "startOfCode", "amount")
Because tbl.Group() adds values together by default, this will give you a table with a row for each distinct value of startOfCode and the subtotal of amount for each of those values. Finally, you can do the lookup exactly as you requested, which for your input table will return 800:
A4: =tbl.Lookup(A3, "startOfCode", "908", "amount")

Resources