Reverse MATCH with a non existing value - excel

I have data in Excel in the following format:
Column A Column B
20/03/2018 300
21/03/2018 200
22/03/2018 100
23/03/2018 90
24/03/2018 300
25/03/2018 200
26/03/2018 100
27/03/2018 50
28/03/2018 90
29/03/2018 100
30/03/2018 110
31/03/2018 120
I would like to get the date where the minimum of B would never be under 99 again chronologically. It the example above, that would happen the 29th of March.
If I try to get it with: =INDEX(A:A,MATCH(99,B1:B12,-1)) the value returned is 22/03/2018 as it is the first occurrence found, searched from top to bottom.
In this case it would be perfect to be able to do a reverse match(e.g. a match that searches from bottom to top of the range) but this option is not available. I have seen that it is possible to do reverse matches with the lookup function but in that case I need to provide a value that is actually in my data set (99 would not work).
The workaround I have found is to add a third column like the following (with the minimum of the upcoming value of B going down) and index match on top it.
Column A Column B Column C
20/03/2018 300 50
21/03/2018 200 50
22/03/2018 100 50
23/03/2018 90 50
24/03/2018 300 50
25/03/2018 200 50
26/03/2018 100 50
27/03/2018 50 50
28/03/2018 90 90
29/03/2018 100 100
30/03/2018 110 110
31/03/2018 120 120
Is there a way of achieving this without a third column?

The AGGREGATE function is great for problems like these:
=AGGREGATE(14,4,(B2:B13<99)*A2:A13,1)+1
What are those numeric arguments?
14 tells the function to replicate a LARGE function
4 to ignore no values (this function can ignore error values and other things)
More info here. I checked it works below:
If your dates aren't always consecutive, you'll need to add a bit more to the function:
=INDEX(A1:A12,MATCH(AGGREGATE(14,6,(B1:B12<99)*A1:A12,1),A1:A12,0)+1)

=INDEX(A1:A12,LARGE(IF(B1:B12<=99,ROW(B1:B12)+1),1))
This is an array formula (Ctrl+Shift+Enter while still in the formula bar)
Builds an array of the row 1 below results that are less than or equal to 99. Large then returns the largest row number for index.

Related

calculate sumproduct(Excel) in pandas dataframe based on condition

I have a dataframe.Structure:
SEQ product_name prod_cost non-prd_cost mgmt grand_total
1 prod1 100 200 20 320
2 prod2 200 400 30 630
3 prod3 300 500 40 840
4 prod4 100 300 50 450
I want to calculate sumproduct(in excel) based on condition.The condition is based on product_name.
lets say I want to calculate a variable called
sumprod_prod1_prd_prod3_mgmt = SUMPRODUCT(SEQ 1-4,product_name='prod1'_prod_cost and 'prod3'_mgmt)/2 = 100+40=140
How can I do this in pandas?
While I am a bit confused by your question, since the excel SUMPRODUCT function returns the sum of the products of corresponding ranges or arrays, and you seem to want the SUM of a singular combination.
To get the desired value:
sumprod_prod1_prd_prod3_mgmt = df[df['product_name'] == 'prod1']['prod_cost'].values[0]+df[df['prod_name']=='prod3']['mgmt'].values[0]
This solution gives a single result for the specified values. If you need a solution which provides the same functionality as excel, please update your question and example to better define what you are looking for.

Sumif of multiple Index matches against one value

Need help regarding Excel dynamically search based sum of two columns matching from two different tables.
I have got this Table of Data Entered One Time
A B C
1 Qlty Warp Weft
2 Stpl.1 150 20
3 Cotn.1 80 60
4 Stpl.2 20 20
5 Cotn.2 20 20
6 Stpl.3 20 40
in Column A2:A6, Quality can not be duplicated, its a unique Name
The Data entry and report Table is here
A B C D E F
8 Yarn Name Sent Bags Remaining Qualty Used Warp Used Weft
9 20 800 600 Stpl.1 71 200
10 150 101 30 Stpl.2 70 30
11 40 300 290 Stpl.3 100 10
12 20 400
C9:C5000 is Returning Column, Values are calculated on the base of Column A9:A5000 (Yarn Name)
Need to Find Yarn Name (eg:) "20" in B2:B6 AND/OR C2:C6, wherever it matches, index that Quality from A2:A6
Then match the returned qualities(could be more than one) to D9:D5000 and sum the mathced results from E9:F5000
I have tried so far in C12
=SUMIF($A$9:$A12,A12,$B$9:$B12)-(SUMIF($D$9:$D12,INDEX($A$2:$A$6,MATCH(A12,$B$2:$B$6,0)),$D$9:$D12)+SUMIF($D$9:$D12,INDEX($A$2:$A$6,MATCH(A12,$C$2:$C$6,0)),$D$9:$D12))
PS:- I am using Excel 2007
If I understand correctly, then following array formula can help you:
=SUM(IFERROR(INDEX($A$2:$A$6,N(IF(1,(MMULT(--($B$2:$C$6=A9),TRANSPOSE(COLUMN($B$2:$C$6)^0))>0)*(ROW($B$2:$C$6))-1)))=TRANSPOSE($D$9:$D$12),0)*TRANSPOSE($E$9:$E$12+$F$9:$F$12))
Array formula after editing is confirmed by pressing ctrl + shift + enter
Edit:
To calculate Warp and Weft columns separately use following array formula:
=SUM(IFERROR(INDEX($A$2:$A$6,N(IF(1,((A9=$B$2:$B$6)*ROW($B$2:$B$6))-1)))=TRANSPOSE($D$9:$D$12),0)*TRANSPOSE($E$9:$E$12))+SUM(IFERROR(INDEX($A$2:$A$6,N(IF(1,((A9=$C$2:$C$6)*ROW($C$2:$C$6))-1)))=TRANSPOSE($D$9:$D$12),0)*TRANSPOSE($F$9:$F$12))

Divide excel column to N equal groups

I have a column with ordinal values. I want to have another column that ranks them in equal groups (relatively to their value).
Example: If I have a score and I want to divide to 5 equal groups:
Score
100
90
80
70
60
50
40
30
20
10
What function do I use in the new column to get this eventually:
Score Group
100 5
90 5
80 4
70 4
60 3
50 3
40 2
30 2
20 1
10 1
Thanks! (I'm guessing the solution is somewhere in mod, row and count - but I couldn't find any good solution for this specific problem)
If you don't care about how the groups are split for groups that aren't evenly divisible, you can use this formula and drag down as far as necessary:
= FLOOR(5*(COUNTA(A:A)-COUNTA(INDEX(A:A,1):INDEX(A:A,ROW())))/COUNTA(A:A),1)+1
Possibly a more efficient solution exists, but this is the first way I thought to do it.
Obviously you'll have to change the references to the A column if you want it in a different column.
See below for working example.

Excel formula for greater than but less than with several tiers

I have a few hundred rows of data, and each has a number between 1 and 200, and I'd like to put them in categories of 1-5 depending on where that number is.
The categories look like this:
Zones Min Max
1 0 35
2 35 60
3 60 85
4 85 110
5 110 200
I want to assign it a Zone if it is greater than the Min, but less than the Max.
I have 2 formulas I've been working with to solve it. One is a nested IF AND statement:
=IF(A1<=35,1,IF(AND(A1<=60,A1>35),2,IF(AND(A1<=85,A1>60),3,IF(AND(A1<=110,A1>85),4,IF(AND(A1<=200,A1>110),2,"TOO BIG")))))
The 2nd formula attempts to use a SUMPRODUCT function:
=INDEX($C$2:$C$6,SUMPRODUCT(--(A1<=$E$2:$E$6),-- (A1>$D2:$D$6),ROW($2:$6)))
Rather than have to continue to adjust the numeric values manually, I set them as absolutes, which is why this formula is slightly different. The E column is the Max value set, and the D is the Min value set.
Any help would be appreciated!
Use this:
=MATCH(A1,{0,35,60,85,110})
Another way is to use VLOOKUP and you just need to set the min number:
=VLOOKUP(D2,$A$2:$B$6,2,1)
The key is the 4th parameter needs to set to 1 which means TRUE. It will find the closest value and return the zone for you.
But noticed that you have overlaps like 35 or 60 etc. that you will need to adjust your value column.

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