I have two columns. One with positive values and one with negative values. I need to find the absolute difference between the two columns.
What I am currently doing is the following: First of all, I edit both the columns to make all the values positive. Then I subtract the first column with the second column. I change any negative value to the positive one. Is this the same as the absolute difference?
Why not just use the ABS function
=ABS(B1-A1)
It sounds like what you're doing is actually
=ABS(ABS(B1)-ABS(A1))
which is not the same as
=ABS(B1-A1)
for example if you have -3 and 1 the first would give you 2 and the second would give 4. I don't know which one you want.
This works no matter which value is positive or negative:
=MAX(A1,B1) - MIN(A1,B1)
OK, so here's a pretty clunky workaround, but it is something where I can understand what's going on and works every time.
Here is my scenario where I needed to solve this problem. I had a system stock list showing 1 of these 10 of those but also showing -10 of these and 5 of those, and once entering my physical data from doing a stock take, I had pluses and minuses all over the place, so the data looked like this:
Physical stocktake value system value
0 0
1 0
1 2
0 -1
1 -1
Effectively all the different connotations of pluses and minuses.
so column 'a' is actual, column b is system
I created columns c,d,e,f ..... I warned you it was a little clunky, but it is sound in the result.
formula in column c = '=IF(A1>B1,A1+B1,A1-B1'
formula in column D = '=IF(B1+C1<>A1,A1-B1,C1)'
formula in column E = '=IF(D1>C1,C1,D1)'
Column E is the data you want, it rationalises all of the pluses and Minuses in your data to show a true difference (independent of positive and negative location) for the values you require.
Someone much cleverer than I will condense this down into a singular equation, but i read up on it, tried the current solutions/advise, and didn't have a clue what the techs were going on about, so came up with this faultless solution.
It does work and it s simply a transpose the A1's and B1's for your data content.
Hope it helps (a little).
I for one will check back, just to pick up on what the clever guys and gals come back with, just a case of life is to short to drive into this level of detail for a simple solution. Sometimes simple is best.
Yeah ok, set myself up for that one ..... so I'm simple, but I know what I'm doing and understand it ........
Related
I am currently doing a formula to find the overall grade for a student that has done 2 exams and 1 assignment.
I have made a formula that can achieve the task, but i have ran into a problem and I dont exactly understand why its giving me the incorrect answer.
As you can see in the screen shot provided you can see the 2 exams and 1 assignment, the grades are, A, A+, B+ which averaged should come out to a a value of 13.66 and as a grade as A (rounded upwards) but when i click out of the cell it shows a C+ and I dont understand why.
=INDEX(L$2:L$16,MATCH(SUMPRODUCT((E8:G8=L$2:L$16)*(M$2:M$16))/COUNTA(E8:G8), M$2:M$16,-1))
The quickest solution since you specified that its only for three scores, is to use the average of three separate lookups, something like:
=AVERAGE(VLOOKUP(E6,gradevalues,2,FALSE),VLOOKUP(F6,gradevalues,2,FALSE),VLOOKUP(G6,gradevalues,2,FALSE))
...where gradevalues is a named range representing the list of lettergrades-to-scores.
eg.,
Your original formula is exactly right.
After hand typing everything in from your example, it works flawlessly.
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.
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.
Little issue I'm having that I'm hoping someone can help me with please?
So I have 3 columns in Excel. Each Column (A/B/C) contains either "high" / "Medium" / "Low" scored issues. However, if you have 3 Low issues, this is grouped together, and this becomes 1 Medium Issue for example.
The difficulty I'm having is writing a formula that will do this for me. Obviously I could just divide the number of Low issues I have by 3, but in the case where I have 7 Low issues, It should result with 2 Mediums and 1 remaining Low. I've tried using the "Mod" function, but that only returns the remainder.
What I need is a formula that will say "If you have 7 Low Issues, (3 low = 1 medium), therefore you have 2 medium and 1 Low). The medium issues would then be added to the Medium Column (Col B), and the remaining low issue is counted in the Low issue column (Col C).
I hope this explanation makes sense, fingers crossed one of you might be able to help me! Thank you in advance
As requested, a screenshot!
If I understand you correctly, I think you should be able to adapt the following formulas to meet your needs.
To get the number of occurrences of the word "Low" in column A:
=COUNTIF(A:A, "=Low")
To get the number of "Mediums" from 3 occurrences of "Low" in column A, round down the above number divided by 3:
=FLOOR(COUNTIF(A:A, "=Low")/3,1)
To get the remaining "Lows" after groupings of 3 into "Mediums", use MOD:
=MOD(COUNTIF(A:A, "=Low"),3)
Putting this into a worksheet:
Values
Formulas
Finally, if you wanted one "Mediums" count, i.e. adding the remaining "Mediums" which aren't grouped into "Highs", you would use a combination of the above formulas for what is left after grouping to "Highs" with what is gained from grouping of "Lows".
Edit:
Now you've included an image, I can show how these formulas are directly applicable...
Values
Formulas
Sounds like you were already nearly there with using =MOD() just needed a little tweak:
For the high column:
=COUNTA(A2:A8)+FLOOR(COUNTA(B2:B8)/3,1)
For the medium column:
=FLOOR(COUNTA(C2:C8)/3,1)+MOD(COUNTA(B2:B8),3)
For the low column:
=MOD(COUNTA(C2:C8),3)
It's exactly like a long addition that you do at school where each column carries over to the one to the left of it (except base 3 instead of base 10). I'm not clear that existing answers cover the case where there is a carry from one column and that causes a further carry from the next column so here is another answer
In the totals row (e.g. for the medium column) in (say) C12
=COUNTA(C2:C10)+INT(D12/3)
Then use mod as before
=MOD(C12,3)
except that in the high column you don't want to use MOD so it's just
=B12
I'm trying to subtract 2 timepoints which excel is registering as negative when it shouldn't be. Time 1= 00:40 and Time 2=00:20 . Time 1- Time 2 should equal 00:20 but Excel seems to think this is a negative number. The formula I have is a bit more complex as it involves a Look Up function and I only have this problem on 2 of the lookup values (Other values are 00:45 and 01:00). Any thoughts would be much appreciated!
Thanks
I deleted one of the lookup values and it's registering the correct time now. Might be because one of the words in the lookup vector/value repeated itself (e.g. a in one cell and a b in a cell further down). I'm guessing Excel got confused? Although both result vectors in this case had the same time (00:20) so don't know what's going on there!