I have an array in excel that looks something like this, though much larger:
A B C D E F G
0 0 0 0 2.78 2.48 2.11
0 0 0 3.11 2.94 2.78 2.15
0 0 0 2.72 2.7 2.2 2.15
0 1.68 2.44 2.29 2.13 0 0
1.89 1.97 2.43 2.07 0 0 0
I'm trying to find all the values within an interval, then replace them with a different value according to a chart that looks like the one below. The values in the first row are the limits of an interval, and the second row represents the value I would like to insert into the array above. For example, the value in cell A5= 1.89. 1.89 falls between 1.8 and 1.9 so according to the chart below I would like the output to be 19.9192.
A B C D E F G ........>
1.6 1.7 1.8 1.9 2 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3 3.1 3.2
19.51 19.721 19.9192 20.1088 20.2903 20.4644 20.6318 20.7928 20.9484 21.0986 21.2441 21.3849 21.5214 21.654 21.7829 21.9083 22.0304
In terms of finding the values, I've tried the following :
=AND(A1 > Lower limit ,A1< Upper limit)
And using the Lower/ Upper limits as neighboring cells in the chart. For example,
=AND (A1> A10, A<A11)
which returns a value of either FALSE or TRUE depending of if the cell A1 is within the specified interval. I realize this isn't quite right but I'm not sure how to proceed. If its TRUE, I'm not sure how I can then insert the value I want based on the second chart - for example 19.9192 if the value was between 1.8 and 1.9, and if FALSE, I'm not sure how I can than move on to check the next interval and keep checking intervals until the right one is found an the cell is replaced appropriately. I think a loop might be needed, but I've not worked much with excel and haven't been able to get any syntax right to try it out.
A second look at your reference data, the format is in precision of 0.1. Whereas the input data is of 0.01 and 0.1. another condition is you take the lower bound of the difference. Thus, I would roundup the value 1st, then query the ref table using it. eg. 1.89 > convert to 1.8 > look for 1.8 pair value > retrieve value.
in I2 enter :
=IFERROR(INDEX($11:$11,MATCH(INT(A1*10)/10,$10:$10,0)),"") and drag it until O6.
+----[formula breakdown:]----+
round the number to 0.1 precision > INT(A1*10)/10
look for 1.8 position in the selection > match()
retrieve the value from the position identified > index()
hope that helps. (:
Related
How can I format a number in Excel so that if it's a whole number with a decimal, it goes to the 10th, but if it doesn't have a whole number it goes to 100th?
Example:
0.08 -> 0.08
0.02 -> 0.02
1.66 -> 1.6
2.55 -> 2.5
2.89 - > 2.8
3.66 -> 3.6
5 -> 5
8 -> 8
Edit:
So far the formula provided by JvdV is working
=IF(A1-INT(A1)>0.1,ROUNDDOWN(A1,1),A1)
but needs to adjust for the following:
1) I need anything with 0.1 to contain its original value. With the current formula above this changes 0.15 to 0.10.
Example:
0.11 -> 0.11
0.15 -> 0.15
0.16 -> 0.16
0.19 -> 0.19
2) The formula needs to round up .01 to .09 only when they have a whole number in front of them.
Example:
0.01 - > 0.01
0.07 -> 0.07
0.09 -> 0.09
0.99 -> 0.99
1 -> 1
1.01 -> 1.1
1.02 -> 1.1
1.04 -> 1.1
1.05 -> 1.1
1.06 -> 1.1
1.07 -> 1.1
1.08 -> 1.1
1.09 -> 1.1
2.01 -> 2.1
2.04 -> 2.1
3.03 -> 3.1
3.09 -> 3.1
This is tricky because 0.01 should be formatted as 0.01. 0.02 should be formatted as 0.02, etc. Currently, the formula does this but does not round up for whole numbers.
I guess something like this could work:
=IF(A1-INT(A1)>0.1,ROUNDDOWN(A1,1),A1)
After your edited question, my edited answer would look like:
=IF(A1>1,IF(A1-INT(A1)>0.1,ROUNDDOWN(A1,1),ROUNDUP(A1,1)),A1)
You can use this formula:
=IF((INT(A1)=A1)=FALSE,IF(AND(A1>0,A1<1),TRUNC(A1,2),TRUNC(A1,1)),A1)
One more formula option:
=ROUNDDOWN(A1,(MOD(A1,1)>0)+(INT(A1)=0))
If you are okay with whole numbers also showing 1 decimal place (so 5 -> 5.0) then you can use a custom number format (there is also ways to use this method to hide the decimal on a whole number, but that would also require a using conditional formatting).
Select the range you want to format, then right click. Click on Format Cells, then select the Custom category.
Enter this in the 'Type' field:
[<1]0.00;0.0
Pros:
Doesn't require a helper column
Retains the original cell value. (If this is not desirable, then you can simply round or truncate the number. But this would require a formula [hence helper column] or possibly VBA)
Cons:
Will still format a whole number with .0. So 5 -> 5.0
You can find more information about custom format codes here: https://support.microsoft.com/en-us/office/number-format-codes-5026bbd6-04bc-48cd-bf33-80f18b4eae68
I am trying to create a formula in Excel that returns the highest decimal value for every integer in a list.
For example, my sheet may have the values [10, 10.1,10.4, 11.3] and I need it to return both 10.4 and 11.3 since 10.4 is larger than 10 and 10.1, and 11.3 is the largest decimal value for 11.
I need this so that a pivot table can filter out the values as IDs and only return the highest value, but I can't get anything working to the point that providing my existing 'code' wouldn't help whatsoever.
Thanks for the help
If your list is sorted, you could use the Advanced Filter to generate a list of the highest decimal value for each integer.
Given:
Criteria Formulas:
A2: =A6<>INT(A6)
B2: =OFFSET(A6,1,0)=INT(OFFSET(A6,1,0))
Criteria Dialog
Note that you can choose to have the results copied elsewhere
Results
Solve as follows:
value bracket decimal
10 =int(a2) =a2-b2
10.4 =int(a3) =a3-b3
10.1 =int(a4) =a4-b4
11 =int(a5) =a5-b5
11.3 =int(a6) =a6-b6
or values:
value bracket decimal
10 10 0
10.4 10 0.4
10.1 10 0.1
11 11 0
11.3 11 0.3
Now pivot by:
bracket (columns/rows)
and in the value section add the "original value", aggregate by "max".
Pivot table and then group.
pivot table
change PivotTable Fields values to Max of values
group
result
I have a list of numbers that I need to count, however I need to count the 0.00 but not the 0's. For example:
0
0.00
2.85
6.68
1.35
3.27
5.24
5.42
3.32
7.20
0
0
I would need this to count 9 and exclude the three 0's
I have tried using a COUNTIF formula but it seems to be treating the 0.00 and 0 in the same way which isn't giving me the result I need.
Any help would be appreciated as I'm unable to think of any other way around this.
If you format the list of numbers as Text then the COUNTIF formula will respect the difference between 0 and 0.00. See this example below.
Both B1 and E1 have a similar formula:
=COUNTIF(D1:D12,"<>0")
But the range D1:D12 has been given a format of text and so includes the 0.00 therefore giving the answer you want - 9.
I'm doing a table with the best outputs of an experiment. In this table I need to display the best (maximum) result for every combination of Sample and Method. And also the Test that gave this best result.
After checking similar questions here, I got how to do the first part (MAX result), but got no solution for the second part (label/test giving that result).
Here's a simplified table to see if you can help me to understand how to do that:
Data Table
A B C D E
1 Test1 Test2 Test3
2 Sample1 Method1 1.6 2.2 0.1
3 Sample2 Method1 1.5 1.3 0.6
4 Sample3 Method1 1 0 0.6
5 Sample1 Method2 0.5 0.1 1.7
6 Sample2 Method2 1.5 0.5 1
7 Sample3 Method2 0.4 0.5 2.7
8 Sample1 Method3 0.7 1.7 1
9 Sample2 Method3 1.1 1.1 1.2
10 Sample3 Method3 0.6 0.4 1.5
And here Is a draft of the table I hope to build
G H I J K L M
1 BEST Sample1 Sample1 Sample2 Sample2 Sample3 Sample3
2 RESULTS ValMax Test ValMax Test ValMax Test
3 Method1 2.2 1.5 1
4 Method2 1.7 1.5 2.7
5 Method3 1.7 1.2 1.5
As you can see I already get how to check which was the maximum value of each combination, thanks to this array function (at H3):
=MAX(IF(($A$2:$A$10=H1)*($B$2:$B$10=G3);$C$2:$E$10))
(and Control + Shift + Enter )
But for the second part I have no clue. I need to extract, from the "row 1", which of the 3 Tests (Test1, Test2 and Test3 at Columns C, D and E) contains the MAX value for the Row that contains the right combination of Sample and Method.
I tried with something like this (at I3):
=INDEX($A$1:$E$10; 1; MATCH(H3&H$1&G3; $C$2:$E$10&$A$2:$A$10&$B$2:$B$10;0))
(and Control + Shift + Enter )
But is obviously not working, because I'm mixing rows and columns.
How do I get the value from row 1 (Test) that corresponds with the Maximum value of the combination of Method and Sample?
Although I'd probably use VBA to construct the table, the following formula will return the Test that corresponds to the sample:
I3: =INDEX($C$1:$E$1,1,MATCH(H3,INDEX($C$2:$E$10,MATCH(TRUE,IF((I$1=$A$2:$A$10)*($G3=$B$2:$B$10),TRUE),0),0),0))
You will need to adjust addresses for the different columns, or combine this with your other formula in an IF function to decide whether to display the score or the test name.
Here is a non CSE Array formula that will do it:
=INDEX($C$1:$E$1,MAX(INDEX(($G3=$B$2:$B$10)*($A$2:$A$10=I$1)*($C$2:$E$10=H3)*(COLUMN($C$2:$E$10)-COLUMN($C$2:$C$2)+1),)))
I have to show 3 conditions using Conditional formatting.
If the % change in the cost driver is more than .25% higher or lower than the % change in actual price.
More than .25% - Red
Less than .25% - Green
In between - Yellow
I'm able to get the first two, but not the third one.
For Green, I used this formula - =if(1.30-1.40/1.30)-(1,210-1,170/1,210)<.25, For Red =if(1.30-1.40/1.30)-(1,210-1,170/1,210)>.25
I tried using Between and Median for Yellow (-0.25% and 0.25%), but does not seem to be working.
Product Location Jul-13 Aug-13 Sep-13 Oct-13
1 A 1.40 1.30 1.34 1.47
2 B 1.43 1.43 1.46 1.47
3 C 1.40 1.41 1.45 1.46
Driver 1,170 1,210 1,260 1,225
Unless I've got the wrong end of the stick here, it looks to me as though you currently have:
for red: if < -0.25%
for green: if > 0.25%
for yellow: if (<= 0.25% OR >= -0.25%)
None of the data you provided match the condition for yellow, hence you aren't getting any results.
Using E17 and F17 as the demo cells, you could do:
=IF(AND((F12-E12)/E12*100<=0.25,(F12-E12)/E12*100>=-0.25),"Yellow",IF((F12-E12)/E12*100>0.25,"Green",IF((F12-E12)/E12*100<-0.25,"Red")))
If E17 is 1170 and F17 is 1171 you will have "Yellow" output. 0.25% higher or lower you will have "Green" or "Red" output respectively. You can use text conditional formatting from the word.