Changing the numbers in two different intervals - excel

Currently I am using the following formula:
=1 + (FLOOR((ROW()-2);5) / 5) + (FLOOR((ROW()-2);5) / 5) * 6
to change the numbers by 7 in different intervals and everything is working fine and you can see column A. But numbers should change by 15 for every 5th change and again the rest 4 changes should change by 7 (see in column B):
.
Is it possible to build a formula like that?

I changed your formula a bit to be shorter and a little safer:
=1+(INT((ROWS($C$1:C2)-2)/5)*7)+INT((ROWS($C$1:C2)-2)/20)*8
The first part alone would be =1+(INT((ROWS($C$1:C2)-2)/5)*7) and the added part takes care of the changes at the 5th change.
Hopefully, that will suit your needs better!
Addendum:
Couple of notes regarding the formula:
INT((ROWS($C$1:C2)-2)/5)*7
^ ^
a b
a gives the frequency when 'change' of b has to be applied. So in the above, 7 will be added after 5 rows, and extending the logic to the other part of the final formula, 8 is being added on top of the first 7 (total 15) added every 20 rows (i.e. after 4 changes each of 5 rows).

I believe what you are looking for boils down to adding another 8 every 20th row. This can be achieved by adding FLOOR((ROW()-2)/20;1)*8 to your formula.

Related

Random numbers to a sum of constant value in excel

I would like to generate 14 random numbers in excel between a certain range (3 to 5) that adds up to a certain value lets say 48. The numbers generated between 3 to 5 can be repeated.
I used the =RANDBETWEEN(3,5) from columns D5:Q5. And then in another sheet where I want the result to be displayed I wrote =ROUND(Sheet5!B2/SUM(Sheet5!$B$2:$O$2)*48,0)
Everytime I press F9 it generates random numbers that is fine. But not everytime the total adds up to 48. Sometimes the sum is higher and sometimes the total is lower than 48. How can I make it to a total of 48 instead of random sum.
So set it up - I laid it out like this but you can change that:
You can add flexibility by bringing the constraints for the 3 and 5 onto the sheet - which keeps them visible when you keep trying different scenarios. Like this:
So, based on the comment:
Went back to the other method to state the constraints.

count how often a piece of information appears and calculate that average

I do not want to know the traditional frequency or the traditional averages; so I'll give an example below:
I have this data:
1
3
5
5
2
3
5
5
1
3
The analysis that I would like to obtain is the following:
for example number 1 appears once every eight rows, number 3 appears once every four rows, number 5 appears twice every two rows....
I did it by hand, but now I have more than 21000 rows of data and I'm stuck.
I searched but I can not find a function that does it; But before I started developing my own, I decided to ask for a guide on how to achieve it.
I believe that I was able to achieve the desired result:
The formula is:
Or, if you want to copy/paste:
=IF(CONCATENATE("1-",MATCH(D1,INDIRECT(ADDRESS(MATCH(D1,A1:A17,0)+1,1,4)&":A17"),0))="1-1",CONCATENATE("2-",MATCH(D1,INDIRECT(ADDRESS(MATCH(D1,A1:A17,0)+2,1,4)&":A17"),0)-1),CONCATENATE("1-",MATCH(D1,INDIRECT(ADDRESS(MATCH(D1,A1:A17,0)+1,1,4)&":A17"),0)))
Note that the IF function solves the duplicates (like the number 5). In case you have triplicates you will have to add another instance of IF and adjust the formula accordingly.
Hope that helps!
Well this doesn't exactly reproduce your results, but you could start by looking at the max and min separation of the numbers:
=IF(COUNTIF(A$1:A$10,C2)<=1,"",MIN(IF((ROW(A$1:INDEX(A$1:A$10,COUNTIF(A$1:A$10,C2)+1))>1)
*(ROW(A$1:INDEX(A$1:A$10,COUNTIF(A$1:A$10,C2)+1))<=COUNTIF(A$1:A$10,C2)),
FREQUENCY(IF(A$1:A$10<>C2,ROW(A$1:A$10)),IF(A$1:A$10=C2,ROW(A$1:A$10)))))+1)
=IF(COUNTIF(A$1:A$10,C2)<=1,"",MAX(IF((ROW(A$1:INDEX(A$1:A$10,COUNTIF(A$1:A$10,C2)+1))>1)
*(ROW(A$1:INDEX(A$1:A$10,COUNTIF(A$1:A$10,C2)+1))<=COUNTIF(A$1:A$10,C2)),
FREQUENCY(IF(A$1:A$10<>C2,ROW(A$1:A$10)),IF(A$1:A$10=C2,ROW(A$1:A$10)))))+1)
This gives the min or max number of rows between each occurrence of the particular number.
Must be entered as an array formula using CtrlShiftEnter
You could add other statistics (like mean, standard deviation) the same way although the average could be calculated just by (lastrow-firstrow)/(count-1) e.g. for 5 it would be (8-3)/(4-1)=5/3.

Excel Sumif, Sumifs with partial strings in multiple columns?

So this is the simplified question I broke down from a former question I had here: Excel help on combination of Index - match and sumifs? .
For this one, I have Table1 (the black-gray one) with two or more columns for adjustments for various order numbers. See this image below:
What I want to achieve is to have total adjustments for those order numbers that contain the numbers in Total Adjustment column in the blue table, each of which will depend on the cell beside it.
Example: Order number 17051 has two products: 17051A (Apple) and 17051B (Orange).
Now what I want to achieve in cell C10 is the sum of adjustment for both 17051A and 17051B, which will be: Apple Adjustment (5000) + Orange Adjustment (4500) = 9500.
The formula I used below (and in the image) kept giving me error messages, and this happens even before I add the adjustment for Orange.
=SUMIF(Text(LEFT(Table1[Order Number],5),"00000"),text(B10,"00000"),Table1[Apple Adjustment])
I have spent the whole day looking for a solution for this and didn’t even come close to find any. Any suggestion is appreciated.
Assuming your headers always have the text "adjustment" in them, you could use:
=SUMPRODUCT((LEFT($B$4:$B$7,5)=B10&"")*(RIGHT($C$3:$F$3,10)="adjustment")*$C$4:$F$7)
In C10 you could add two sumproducts. This assumes that products are always 5 numbers long at the start. If not swop the 5 to use the length of the product reference part you are matching on.
=SUMPRODUCT(--(1*LEFT($B$4:$B$7,5)=$B10),$D$4:$D$7)+SUMPRODUCT(--(1*LEFT($B$4:$B$7,5)=$B10),$F$4:$F$7)
Which with table syntax is:
=SUMPRODUCT(--(1*LEFT(Table1[Order Number],5)=$B10),Table1[Apple Adjustment])+SUMPRODUCT(--(1*LEFT(Table1[Order Number],5)=$B10),Table1[Orange Adjustment])
Using LEN
=SUMPRODUCT(--(1*LEFT(Table1[Order Number],LEN($B10))=$B10),Table1[Apple Adjustment])+SUMPRODUCT(--(1*LEFT(Table1[Order Number],LEN($B10))=$B10),Table1[Orange Adjustment])
I am multiplying by 1 to ensure Left, 5 becomes numeric.

Excel Rolling Mean of 3 Similar Consecutive Observations

I'm trying to find the rolling mean of time series while ignoring values that do not follow the trend.
x
869
1570
946
0
1136
So, what I would want the result to look like is...
x | y
869 | 0
1570 | 0
946 | 1128.33
3 | 0
1136 | 1217.33 ([1136+1570+946]/3)
900 | 2982 ([946+1136+900]/3)
860 | 2896
The tough part here is if the row I'm on is a trending value I want to take the 3 previous trending values and find them mean of them, but if it's a non-trending value I want it to just zero out. Sometimes I might have to skip 2 or 3 previous lines to get 3 trending values to take the average as well.
So far I've been using array, RC formulas in a VBA macro form, but I'm not sure I could use RC here or if it has to be something else completely. Any help would be greatly appreciated.
I believe I can help you with your problem. First three notes:
1) It appears to me that you are trying to do DCA on smoothed production profiles, ignoring months without a complete record or no data. I'm making this assumption since you mentioned this was time series data but didn't give a sample rate. 2) I've added some extra 'data' for the sake of demo-ing. 3) In your example you shared, the last two values in your 'Y' column it looks like you may have summed but have forgotten to divide.
The solution I came up with has three parts: 1) create a metric to identify 'outliers'; 2) flag 'outliers'; 3) smooth non-flagged data. Let's establish some worksheet infrastructure and say that your production values are in column B and the associated time is in column A as follows:
Part 1) In column 'C', estimate a rough data value based on a trend approximated from two points on either side of your current time step. Subtract the actual value from this approximation. The result will always be positive and quite large for a timestep with little or no production.
=(INTERCEPT(B1:B6,A1:A6)+(A4*SLOPE(B1:B6,A1:A6)))-B4
Part 2) In column 'D', add a condition for when the value computed above is larger than the actual data point. Have it use '0' to identify a point that shouldn't be included in your average. Copy this down to the end of your data as well.
=IF(C4>B4,0,1)
Our sheet now looks like this:
3) Your three element average can now be computed. In the last cell of column 'E', enter the following array formula. You have to accept this formula by pressing ctrl + shift + enter. Once that is done fill the column from bottom to top:
=IFERROR(IF(D17=1,AVERAGE(INDEX(B12:B17,MATCH(2,1/(FIND(1,D12:D17)))),INDEX(B12:B16,MATCH(2,1/(FIND(1,D12:D16)))-COUNTIF(D17,"=0")),INDEX(B12:B15,MATCH(2,1/(FIND(1,D12:D15)))-COUNTIF(D16:D17,"=0"))),0),"")
This takes averages the most recent three values and allows for a skip of up to three time steps of outlier data per your problem statement. For an idea of how the completed sheet looks:
This was a fun challenge, I have some ideas for a more efficient formula but this should get the job done. Please let me know how this works for you!
Cheers
[EDIT]
An alternative approach which allows the user to specify the number of previous entries to include is detailed below. This is a more general (preferred alternative) and picks up in place of the previously described step 3.
3Alt) In cell G2 enter a number of previous values to average, for this example I am sticking with 3. In cell E4 enter the following array expression (ctrl+shift+enter) and drag to the end of column E:
=IFERROR(IF(D4=1,SUM(INDEX(D:D,LARGE(($D$4:D4=1)*ROW($D$4:D4),$G$2)):D4 * INDEX(B:B,LARGE(($D$4:D4=1)*ROW($D$4:D4),$G$2)):B4)/$G$2,0),"")
This uses the LARGE function to find the 'nth' largest value, where n is the number of preceding values from the current time-step to average. Then it builds a range that extends from the found cell to the current time step. Then it multiplies the flags (0's and 1's) by each month's production value, sums them and divides by n. In this way months flagged as bad are set to 0 and not included in the sum.
This is a much cleaner way to achieve the desired result and has the flexibility to average different periods of time. See example of the final value below.

Calculating cited half-life for articles in Excel

Per Ana Andres, "[t]he cited half-life is the number of years, counting back from the current year, that account for 50 per cent of the total citations received by the journal in the current year."
I am trying to calculate this using a formula in Excel. Assume I have data as follows:
2008 2009 2010 2011 Total
0 4 1 3 8
The article was published in 2008, the current year is 2011. In this case the cited half-life is 2, since you have to go back to 2010 to get (1+3) 4 (i.e. 50% of 8) citations.
How can I write a formula in Excel that calculates the half-life in this manner using data structured as above (i.e. each column is one year)?
Paste your values as you have in range A1:E2 and then use the array formula below. You apply array formula by pasting it into a cell and pressing left ctrl + left shift + enter then when yiu select the cell with formula the formula will be shown as if it was in curly brackets i.e. {=max...}.
=MAX(IF(MMULT(((A1:D1)>=TRANSPOSE(A1:D1))*A2:D2,ROW(INDIRECT("a1:a"&D1-A1+1))*0+1)>SUM(A2:D2)/2,TRANSPOSE(A1:D1)))
Briefly
1) creates vector of 1s of a length equal to the number of years
ROW(INDIRECT("a1:a"&D1-A1+1))*0+1
2) provides the vector of years to pic from
TRANSPOSE(A1:D1)
3) provides matrix to calculate cumulative sum
(A1:D1)>=TRANSPOSE(A1:D1))*A2:D2
EDIT: I have modified the formula a bit as before it had problems in cases when the half of score was not achievable in any of the years and solved a bit different problem (it was latd whe I published my answer). I also added description how to use an array formula. Please let me know have it worked.
EDIT2: there was unneccessary space afer SUM which caused #VALUE, it was automatically enetered by spellchecker on my tablet.
You can get it with an auxilary row and the countif() function like this
A B C D E
1 2008 =A1+1 =B1+1 =C1+1 Total
2 0 4 1 3 =SUM(A2:D2)
3 =B3+A2 =C3+B2 =D3+C2 =D2-E2/2 =COUNTIF(A3:D3;"<=0")
I don't know a solution without such an xtra row.

Resources