I am trying to find a formula which will compare two dates (Plan 1 minus Plan 2) and determine if they are within ninety days of each other.
The formula I have so far:
{=IF(E1<>"", IF(AND(MIN(IF(C:C=C1, IFERROR(E1-G1, -2), 0))<91, MIN(IF(C:C=C1, IFERROR(E1-G1, -2), 0))>-1), 1, 0), 0)}
The idea is that the array will loop though the Subjects in Column C and for every subject with a non-blank Plan 1 field (Column E), it will loop through the Plan 2 dates in Column G to find the closest one within ninety days. If one exists, the equation will give the Plan 1 a 1.
However, the formula above is not able to handle the dates seen below where there is no exact matching date in Column G.
Thank you for your help.
Scott Craner found the delightful equation below to answer this problem, except for the issue in the image below. It appears to be including a date greater than 90 days (orange highlight).
Use AGGREGATE:
=IF(E2<>"",IFERROR(--(AGGREGATE(15,7,(E2-$G$2:$G$21)/(($C$2:$C$21=C2)*(E2-$G$2:$G$21>=0)),1)<91),0),0)
Related
I'm trying to create a calculated field that displays the growth rate in % from one of the numeric columns in my pivot table.
How can I reference a row above the current cell to calculate the growth rate?
=(Current cell - (Current cell - 1 Row)) / (Current cell - 1 Row)
Pivot table
Year
Count
Calculated Field (YoY Growth)
2019
100
2020
300
100%
2021
600
50%
based on instructions:
=(Current cell - (Current cell - 1 Row)) / Current cell
={""; ARRAYFORMULA(IFERROR(B2:B-(B2:B-B1:B999)/B2:B))}
I agree with player0, that seeing your sheet, data, data types and layout would facilitate helping you.
However, I'll venture a solution, sight unseen.
There are actually many ways to address what I think you're asking. This is just one of them.
Suppose that your source numbers are in range A2:A. Place the following formula in some other open column, in the cell parallel to the top number in your source range:
=ArrayFormula(ARRAY_CONSTRAIN({"";FILTER(({A3:A;""}-A2:A)/{A3:A;""},A2:A<>"")},COUNTA(A2:A),1))
I've added in more "parts" than are probably necessary. But I tried to include controls, seeing as I don't know what your data actually looks like.
An alternative is to place the following simpler formula into the cell one below where the top number in your source range is:
=ArrayFormula(IF(A3:A="",,(A3:A - A2:A)/A3:A))
In either case, you'll want to format the column/range where the results will be as percent (Format > Number > Percent).
Obviously, if your source numbers are in a range other than A2:A, you'll need to adjust the ranges in either formula accordingly.
Referring to the snippet of a pivot table below in the image, there are 6,000 J####### models (i.e. J2253993, J2254008, J2254014 ... etc).
How can the difference between the last Odometer reading and the first Odometer reading for each model be calculated? There is no consistency in the number of recorded months for each model and there is no consistency between the first and last timestamps for each model.
i.e.
For model J2253993:
Desired answer is: 378
Because 2501 minus 2123
For model J2254008:
Desired answer is: 178
Because 1231 minus 1053
... And so on for the remaining 6,000 models
Would a dynamic array be needed?
Messy SUM/INDIRECT Solution
EDIT: A similar formula for Max-Min in column B (my first idea):
=INDEX(INDIRECT("B"&MATCH(E4,A$1:A$50000,0)+1&":B50000"),MATCH("",INDIRECT("B"&MATCH(E4,A$1:A$50000,0)+1&":B50000"),0)-1)-INDEX(B$1:B$50000,MATCH(E4,A$1:A$50000,0)+1)
I abandoned it because the image wasn't showing any empty cells.
EDIT-END
The formula is calculating the C column sums. A drawback is that you have to insert ="" in all the empty cells of column C unless you know a way how the MATCH function returns an empty cell. In the E column write the ID-s starting from the 4th row and in F4 write the formula:
=SUM(INDIRECT("C"&MATCH(E4,A$1:A$50000,0)+2&":C"&MATCH("",INDIRECT("C"&MATCH(E4,A$1:A$50000,0)+2&":C44"),0)-1+MATCH(E4,A$1:A$50000,0)+2))
Copy/Paste down.
If I am understanding you correctly, it looks like you just need to add a sum of the "Odometer Reading Change" column in your pivot table. When I sum them for J2253993 I get 378 like you say.
Pivot table will total all of the rows by model based on the way you have built it, no matter how many rows are there.
I think this is the hardest to date I have had to crack - so hard I had a hard time finding a good headline.
So we have a site where trucks come and buy say Gravel, or sand or other building materials.
Sometimes they also unload demolition waste first.
I need to find out a couple of things
how many trucks (and from what companys) came empty
if they came empty what did they buy from us.
what companys are sending full trucks and what are sending empty trucks.
a tope 10 of materials they will drive to us from to buy even when coming empty to our facility.
a list of all the order numbers that they drove to us til fill and came with empty trucks. ( I have distances linked to order numbers, so now I can estimate the value of our products)
The data I have available:
I have a full data set of when what customer buys what and / or pay to deliver.
E.G.:
I can see the parts I need to split the data into I think it should be something like this
find all unique licence plates
somehow map if they bought materials within 30 minutes of
offloading demolition waste (most trucks will come between 2 and 10
times per day)
Present all this data (on a normal day we have about 800 trucks = 2000 lines since they weigh in, weigh out, and then some buy something = 2 more weigh lines)
I can easily find unique licence plates per day (either by formula or by Excel function Data/delete doublets,
but after that I have no clue where to start.
I think I need some sheets in between, where I somehow mark if a material was bought from an "empty truck" and I need a counter for that .. somehow...
Any help on how to get started is appreciated.
It seems like the best way to start is with a helper column (in the following exampes, I have chosen "Column M") to flag whether the truck arrived empty.
In the helper column, you can use something similar to the following formula.
{=IF(ISBLANK(B2),0,IF(C2="In",0,IF(B2=$B$2:$B$13,IF($C$2:$C$13="In",IF($A$2:$A$13>(A2-TIME(0,30,0)),0,1),1),1)))}
This is an array formula, which means you have to press ctrl+shift+enter after pasting it in the cell. Then you can copy that cell down the column.
Just to explain, the first if statement knows the truck is not arriving empty if Column C is 'In'. The second if statement creates an array and tests to see if other the same truck appears in other rows. The third if statement checks to see if the same truck checked 'In' in the matching rows, and the fourth if statement verifies if the time they checked in was less than thirty minutes ago. You can adjust the length by editing the TIME(0,30,0) function. The format is TIME(hours,minuites,seconds). Unless the truck matches all three of the second, third and fourth if statements, it is marked as coming empty.
Once you have this helper column, just about all of your tasks are quite simple.
1a: How many trucks came empty? Sum Column M
1b: How many trucks from what company? Create a unique list of companies. Then create a COUNTIFS formula based on Column M = 1 and Column K = Company. For example, if C32 had Company B then the formula =COUNTIFS($M$2:$M$13,1,$K$2:$K$13,C32) would return 2
1c: How many times did a truck come empty? Similar to 1b, create a unique list of License Plates, then use a COUNTIFS based on Column M = 1 and Column B = License Plate.
2: Similar to 1b, just use a unique list of products tested against Column F
3: Similar to 1b, just create a second column, next to the first that uses =COUNTIFS($M$2:$M$13,0,$K$2:$K$13,C53,$C$2:$C$13,"In") Which tests that Column M reports the truck did not come empty, that matches the company in Column K and that the truck came 'In' so you don't double count the same truck when it goes 'out'
4: Just sort list created by number 2. You can highlight the range, right-click and select "Sort" > "Custom Sort", then select the column you want to sort on and largest to smallest.
5: There are a couple of different ways, you could do this. The formula
{=TEXTJOIN(", ",TRUE,IF($M$2:$M$13=1,$J$2:$J$13,""))}
(again, entered as an array formula)
would create a comma separated list of order numbers. An alternative if you want a column of order numbers (but would only work if they are actually numbers), is to paste the formula {=MAX(IF($M$2:$M$13=1,$J$2:$J$13,))} in the first row of the column (in my example, its O2) and then {=MAX(IF($M$2:$M$13=1,IF($J$2:$J$13<O2,$J$2:$J$13,)))} in the row below (change the reference to O2 if you pasted it in a different spot)(again, note that both of these are array formulas). Then copy and paste the second formula down the column. When order numbers of trucks that came in empty are exhausted, the formula will report 0.
I'm looking for a non-VBA solution to this problem.
Say I have a graph (in the computer science sense) in a spreadsheet as follows:
A B C D
1 Vertex Neighbors Degree Avg Nghbr Deg
2 A B,C 2 2.5
3 B A,C 2 2.5
4 C A,B,D 3 1.666666667
5 D C 1 3
I've entered columns C and D by hand but I want them to be calculated automatically. I've found reasonable solutions for column C that essentially count the commas and add 1. But for column D, I can't find a solution. I've found countless articles that explain how to lookup one value multiple times in one column, and countless articles that explain how to look up multiple values once in multiple columns, but I can't figure out how to look up multiple values in ONE column, get back an array of values, and then take the average of that array. I'm sure this can be done in VBA but I'd prefer a native Excel solution if one exists.
Obviously I'd like to extend this so that I can do other analyses of a vertex's neighbors. Presumably once I know the method to analyze a "looked-up array" I will be able to use it in other functions as well.
Any help is greatly appreciated.
To get column C:
=LEN(B2)-LEN(SUBSTITUTE(B2,",",""))+1
To get column D use SUMPRODUCT with SEARCH:
=SUMPRODUCT((ISNUMBER(SEARCH("," & $A$2:$A$5 & ",","," & B2 & ",")))*$C$2:$C$5)/C2
I am having some troubles formulating my problem but I hope you understand!
I have a table of firms building production plants in foreign countries in certain years. (Columns A to C).
In a seperate table i have so-called cross-national distance measures (based on the difference in gdp of the countries). (Columns G to M). Note that the distances change per year.
A simplified version of the excel would look like this:
https://new.wu.ac.at/fileadmin/wu/d/i/iib/photo/stack.JPG
What I want is a formula for the manually entered results in column D. It shall give me a result which is the following:
It shall look in which countries the specific company has previously (years before) built plants
It shall find the smallest cross-national distance from the current country to any of the countries previously entered
The value should be for the year of the current plant-construction
Let me illustrate my request with the example result i would want in cell D8:
The formula would have to find a list of countries that were previously entered in this case Turkey and Bulgaria
It would then have to into the second table and give me the minimum of the distances from Kosovo but only to Turkey and Bulgaria
This would have to be done in the rows for 2008 (current year)
I really hope you guys can help me, i figured out a way to find a minimum in a list and i can do it for certain years as well but the issue i am having that excel first needs to find the previously entered countries, memorize them in some kind of array and then use only these countries to consider the minimum distance.
Thank you very much!
Try this "array formula" for D2 copied down
=IFERROR(SMALL(IF(COUNTIFS(A$2:A$11,A2,B$2:B$11,"<"&B2,C$2:C$11,"<>"&C2,C$2:C$11,I$1:M$1)*(G$2:G$31=B2)*(H$2:H$31=C2),I$2:M$31),1),"N/A")
confirmed with CTRL+SHIFT+ENTER
That checks three conditions for your larger table - that the header row matches a qualifying country (using COUNTIFS function based on criteria in the small table), that column G matches the current year and column H matches the current country.
If all those criteria are satisfied then the relevant values in the table are returned, and SMALL finds the smallest. If there's an error (because there are no qualifying values) then N/A is returned
In Excel 2010 or later versions you can use AGGREGATE function instead of SMALL - this is useful because it doesn't require "array entry"
=IFERROR(AGGREGATE(15,6,I$2:M$31/(COUNTIFS(A$2:A$11,A2,B$2:B$11,"<"&B2,C$2:C$11,"<>"&C2,C$2:C$11,I$1:M$1)>0)/(G$2:G$31=B2)/(H$2:H$31=C2),1),"N/A")