I have the following problem. I use excel's SLOPE function. However, I constantly have to adjust the input range manually -> eg sometimes its SLOPE(A2:A50) and then SLOPE(A2:A75), depending how many input variables I have.
Is there a way I can change the function so that it always takes the range up until the last non-empty cell so that I don't have to adjust manually every time?
Many thanks in advance!
Here is a Simple Explanation :
You can just use an intermediate cell to calculate your ranges and then pass those values to the slope function
In the below Example , if X and Y are extended to have any number of obs , the formula will calculate it dynamically.
Related
I have a LAMBDA function nested in a lambda helper function (MAKEARRAY) to create a column with a series of dates. The series starts with the last day of the month defined in cell start_date followed by the last day of the following month. This one month interval goes on a number of times defined by the value in cell number_months.
The formula is the following:
=MAKEARRAY(number_months,1,LAMBDA(r,c,EOMONTH(start_date,r-1)))
I would like:
This sequence to repeat just below.
Repetition needs to take place a certain number of times, as defined by value in number_repeats.
Since I have the series as the row heading of another Sheet, I have tried using TRANSPOSE(ARRAYFORMULA(INDIRECT to select the variable range, rather than generating again the repeated series of dates. However, in such case I have to figure out how to repeat that array a certain number of times without using REPT and SPLIT because it exceeds the character capacity by far.
That being said, if possible my preference is for a solution based on the transposed LAMBDA function that created the row heading in the other Sheet, rather than referring to the heading using ARRAYFORMULA.
I feel I could use SEQUENCE for that, but I am not sure how to combine it with the LAMBDA function to repeat the series a certain number of times.
What do you think of this?? You can change that B1:1 of the last pair of brackets to your own lambda function. For visual purposes (and probably of calculations if they're too long) I used a range of headers in B1:1 and cell A1 to state the "n" number of times.
So, "qt" is the amount of items in the "headers" (done with Counta) and "times" is that number set by you. I used Counta so you could be able to add more items in your headers (or lambda function) and it would be flexible enough to work too.
BYROW displays the range, and SEQUENCE calculates the amount of rows needed (qt*times) and MOD and INDEX iterates through the headers the amount of times needed.
=lambda(qt,headers,lambda(times,byrow(sequence(qt*times),lambda(seq,INDICE(headers,,RESIDUO(seq-1,times)+1))))(CONTARA(headers)))(A1,B1:1)
Here you have a sample sheet: https://docs.google.com/spreadsheets/d/18qaf86Q5eY-F1ffo15ecaS6haKqj55heW8hT4VBLFHc/edit?usp=drivesdk
You can use reduce to repeat an array a number of times:
=reduce("Header",sequence(num_repeats),lambda(total,value,{total;MAKEARRAY(number_months,1,LAMBDA(r,c,EOMONTH(start_date,r-1)))}))
I have formatted the dates manually though.
Thank you very much Tom and Martin,
I also got the following solution from someone who assisted me too:
=MAKEARRAY(1, B1 * C1, lambda(r, c, eomonth(A1,{mod(c-1, B1)})))
I am trying to filter an array to only include those values that are not within a set distance of a change in that array.
Here's my example:
The input array increases monotonically in steps. I want to zero out any of the input values from N rows above to N rows below any point where the value changes. Cell $B$2 holds this "window" value.
For example, cell A9 (value 11) is different from cell A8 (value 5), so I want to zero out values that come from any cells from A7 to A11 inclusive. That is from -N to +N relative the cell where the change occurs, where N=2.
I can achieve the required output with non-array functions, using intermediate calculation columns, but since I am processing a large number of columns it would save greatly on spreadsheet real-estate if I could construct a single array formula that operates on the range A4:A25, and uses cell B1 for the size of N. I am using the current Excel Beta, so I have access to LET and LAMBDA if needed.
I have tried various combinations, using SEQUENCE, but I run into the issue that LET (or indeed any array functions) seems to fail if they contain two SEQUENCE statements.
I am continuing to work on this, but if anyone wants to have a try, I would be most grateful!
UPDATE: This formula does the trick, but needs to be copied down:
=A4*IF(AVERAGE(OFFSET(A4,-($B$1+1),0,2*($B$1+1),1))<>A4,0,1)
So, while the suggestion of #JvdV was not exactly what I was after, a hat-tip to them for the idea of offsetting the whole column up and down, which led to this:
=LET(input,A4:A25,up,OFFSET(input,-1*(B1+1),0),down,OFFSET(input,B1,0),input*IF(IFERROR(up*down,0)>0,IF(up=down,1,0),1))
I have an array of a structures containing two float values x and y.
x is the position on a x-axis in mm (0.0mm to e.g. 2500.0mm)
y is a height measurement in mm at the x-position (0.0mm to e.g. 50.0mm)
With the length of 2500.0mm I will have an array filled up with 2501 values (one for each mm). As i want to send this array to a visualization which will draw that on a x/y plot i want to reduce that array to exactly 500 values (more than 500 values will slow down the communication too much). Now you might say.. well okay, than just take every 5th value. But what to do if my array has 1653 values? I would have to take every 3,306th value. I definitely need the first and the last value.
Is there any elegant algorithm that might help me out?
You could use interpolation to estimate a function that is similar to yours, and then you could just choose the desired points in the data range and estimate their value. Then, you could simply plot these values.
This is elegant and pretty easy to generalize for more or less points, as long as you stay within the range of original data (and do not try to extrapolate out of this range)
I have an array of numbers:
46.50, 46.50, 46.50, 50.00, 60.00, 57.00, 50.00, 48.00, 44.00, 42.00
I'd like to create a formula that finds the maximum positive difference between two consecutive pairs. So in the above example, the intermediate calculation would be:
0,0,-3.50,-10.00,3.00,7.00,2.00,4.00,2.00
Therefore the answer would be 7.00
Going to go with a basic array formula for this one. Aussuming your data is layed out as per the image below, used to offset ranges and subtract one range from the other. Then take the maximum of those results. This can be achieved using the following formula entered as an array. meaning you need to confirm it with CTRL+SHIFT+ENTER. You will know you have done it right when {} show up around your formula. They cannot be added manually.
=MAX(B3:B11-B4:B12)
as an alternative non array formula you can got with AGGREGATE which will perform array like calculations:
=AGGREGATE(14,6,B3:B11-B4:B12,1)
The above formulas will provide you with the largest positive difference. If how ever you need to know the largest difference, then -10 is a larger difference than 7. Its just in the opposite direction. To find this you would need to add ABS to the above equations as follows:
=MAX(ABS(B3:B11-B4:B12))
OR
=AGGREGATE(14,6,ABS(B3:B11-B4:B12),1)
Use an array formaula. If your values are in column A (rows 1 to 10 in this case), use
=MAX(A1:A9-A2:A10)
And enter it with CTRL-SHIFT-ENTER instead of just Enter.
What I would like to do is to count the amount of lines that matches criterias to be verified in two arrays.
I can't use VBA, add new columns (for instance a new column with VLOOKUP formula) and preferably use arrays.
I have two separate ranges, each with a ID column for the identifier and other fields with data.
For instance, range 1:
Range 2:
If I had only to check the first range I would do:
={SUM((D4:D7="Red") * (E4:E7="Big"))}
But I don't know how to check also using data from the other range.
How, for example, to count the number of items that are Red, Big and Round by using both Ranges ?
Put this in the cell F4:
=IF((VLOOKUP(C4,$C$11:$D$12,2)="Round")*(D4="Red")*(E4="Big"),1,"")
Note that the behavior of VLOOKUP is that it finds the value up to the first parameter. Since there's no 1 in your second dataset, this first cell is going to show "#N/A", which I don't know how to solve, but when you extend this formula down to also compare the other sample data in the first set, the ID numbers 2 and 4 will show up as "yes" for you.
Edit: You wanted a count of this list. So after this, it should be easy to get a count of cells in this column using the COUNT function.
Try this array formula
=SUM((D4:D7="Red")*(E4:E7="Big")*ISNUMBER(MATCH(C4:C7,IF(D12:D13="Round",C12:C13),0)))
The last part is the added criterion you want - the IF function returns {2,4} [IDs where Data 3 is "Round"] and then you can use MATCH to compare C4:C7 against that. If there is a match you get a NUMBER (instead of #N/A) so you can then use ISNUMBER to get TRUE/FALSE and that feeds in to your original formula - result should be 2