Related
I have the following 4 rows and I wish to find the decimal length (aka scale) of that decimal value. Do note that I'm importing all of the decimal data in Excel whose cell is formatted in a "Text" format (hence the trailing zeros even after the decimal values). And I do not want to convert it into decimal. I just need to find the scale of that decimal number.
Decimal Number
Scale (Formula?)
106.520000
2
0.080100
4
15.000010
5
265.000000
0
Been struggling for a very long time now. I'd appreciate any lead on this.
This is what I have tried,
• Formula used in cell B2
=LEN(MID(NUMBERVALUE(A2),FIND(".",A2)+1,255))
You could try:
Formula in B2:
=MAX(LEN(-A2)-LEN(INT(A2))-2,0)
Note: I use a decimal comma but it shouldnt matter for you.
I have some data that looks like this
Condition 1
Condition 2
Condition 3
Condition 4
Condition 5
0
0
0
70
0
0
50
10
0
0
120
0
0
5
5
Where the value in each cell is the number of meters of an asset that is the given condition. Or in other words, a count of the number of meters that are a '4'.
How do I calculate a standard deviation for this? Obviously the std.dev would be '0' for the first row, higher for row 2, and fairly low for row 3.
Something similar to REPT, but that repeats a value x times in a formula?
I considered a helper column but the number of meters that there are in total makes this impractical.
I am not a math expert, but I can show you how to "make a range of numbers" based on the criteria shown, using Excel 365.
Suppose your data is in the range B2:F4 as shown below. In cell G2, enter the following formula and drag it down:
=STDEV.P(--FILTERXML("<t><s>"&TEXTJOIN("</s><s>",1,REPT($B$1:$F$1&"</s><s>",$B2:$F2))&"</s></t>","//s[number()=.]"))
The above will calculate the standard deviation using the STDEV.P function, but I am unsure if this is the right function to use as there are many other variations to the original STDEV function.
Regardless, the following part of the formula is able to return a range of numbers as desired:
=--FILTERXML("<t><s>"&TEXTJOIN("</s><s>",1,REPT($B$1:$F$1&"</s><s>",$B2:$F2))&"</s></t>","//s[number()=.]")
You can view this question and the answer by JvdV to understand the use of the FILTERXML function.
Another way of doing it is to use the alternative SD formula
which would give you
=SQRT((SUM(A2:E2*COLUMN(A2:E2)^2)-SUM(A2:E2*COLUMN(A2:E2))^2/SUM(A2:E2))/SUM(A2:E2))
for the population standard deviation.
The Excel 365 version using Let is more readable I think:
=LET(x,COLUMN(A2:E2),
mpy,A2:E2,
n,SUM(mpy),
sumxsq,SUM(mpy*x^2),
sumsqx,SUM(mpy*x)^2,
numerator,sumxsq-sumsqx/n,
SQRT(numerator/n)
)
A bit less obviously, you could get it from the original formula
=SQRT(SUM(A2:E2*(COLUMN(A2:E2)-SUM(A2:E2*COLUMN(A2:E2))/SUM(A2:E2))^2/SUM(A2:E2)))
Again, in Excel 365 you could write this as:
=LET(x,COLUMN(A2:E2),
mpy,A2:E2,
n,SUM(mpy),
xbar,SUM(mpy*x/n),
numerator,SUM(mpy*(x-xbar)^2),
SQRT(numerator/n)
)
Change the denominator to
(SUM(A2:E2)-1)
for the sample standard deviation.
I ended up figuring it out.
I added a column which calculated the average. (Say column F)
I then had a formula like this
=SQRT(SUM(A2*POWER((1-F2),2),B2*POWER((2-F2),2),C2*POWER((3-F2),2),D2*POWER((4-F2),2),E2*POWER((5-F2),2))/SUM(A2:E2))
Essentially this calculated the variance from the mean for each condition value, multiplied by the number of values (e.g. number of meters) of asset that are that particular condition, then did the normal other standard deviation calculations (sum, divide by total, square).
I have a list of values that looks like this. Every 30min the top row in my data is shifted down and a new latest value is inserted. I'd like to be able to take the average of all the values in the model column from 18:30 to the top most cell each day (so just the latest cell that has an 18:30 value to the top most cell)
Any help would be greatly appreciated
I've been able to find the row that contains the date I need using this:
=MATCH(DATE(YEAR(TODAY()),MONTH(TODAY()),DAY(TODAY()-1))+TIME(18,30,0),AF47:AF4595,0)
So now I just need to able to average from row 1 to the output of that formula. I've tried Index(NamedRange,1:3,0) but that didn't work
=INDEX(AF:AF,1):INDEX(AF:AF,MATCH(DATE(YEAR(TODAY()),MONTH(TODAY()),DAY(TODAY()-1))+TIME(18,30,0),AF47:AF4595,0))
Although I would change your formula just to shorten it...your formula is more readable. I would change your formula to:
MATCH(INT(TODAY())-1+TIME(18,30,0),AF:AF,0)
I was assuming your data was all in AF based on your formula. Adjust AF to match the column of your needs.
Since INDEX returns a cell address, you just need to wrap the range defined by the two indexes in an AVERAGE function:
=AVERAGE(INDEX(AF:AF,1):INDEX(AF:AF,MATCH(DATE(YEAR(TODAY()),MONTH(TODAY()),DAY(TODAY()-1))+TIME(18,30,0),AF47:AF4595,0)))
This is pretty ugly and a roundabout way of doing it, but you can first identify the last row you care about using sumproduct() and some sneakiness. And then pump that into your =Average() formula using Indirect:
=AVERAGE(INDIRECT("B1:B" & SUMPRODUCT((HOUR(A:A)=18)*(MINUTE(A:A)=30)*ROW(A:A))))
It's going to be SLOW though hitting up all of A:A so maybe narrow that range down like A1:A1000 or whatever row is likely to be the max possible row to hold that 18:30 time.
Here is another way using AVERAGEIF:
=IF(NOW()-TODAY()<5.5/24,AVERAGEIF(A:A,">" & (TODAY()-5.5/24),B:B),AVERAGEIF(A:A,">" & (TODAY()+18.5/24),B:B))
It first checks if the current time is before 18:30 then calculates the average as described (from the last 18:30 to now)
An AVERAGEIF/AVERAGEIFS can solve your problem but I see at least three problematic areas.
The 18:30:00 time you want to stop at may or may not be in the same day as the day in the top of the Prediction Area column. This means that you cannot construct a limiting date time from the day at the top of column AF and add TIME(18, 30, 0). You might need to subtract a day if the top of column AF is after midnight and before 18:30:00. A TRUE is considered 1 in a worksheet formula and FALSE is considered zero so taking the date at the top of column AF and subtracting
'Is the time of the datetime in AF47 less than 18:30:00?
(MOD(AF47, 1)<TIME(18, 30, 0))
will make the deciding date today or yesterday depending on the time in AF47.
Your program is inserting Prediction Area datetimes and Model numbers at the top of the list. Depending on the method, this can disrupt conventional formula range addressing, even when using absolute row references. While INDIRECT can be used to 'lock' a cell address by converting from a text string, INDEX is a more efficient method.
'cell address with 'absolute' row (will change with inserted rows)
AF$47
'INDIRECT method (will not change with inserted rows)
INDIRECT("AF47")
'better INDEX method (will not change with inserted rows)
INDEX(AF:AF, 47)
'range of datetimes in column AF
INDEX(AF:AF, 47):INDEX(AF:AF, 95)
Time values typically resolve to pseudo-irrational numbers (aka *repeating decimals') that cannot be relied upon in Excel's 15 significant digit floating point mathematics. For this reason you should use the 00:30:00 interval to ensure true comparity by avoiding >= and <= in favor of > and < against a time value offset by a second. IOW, 18:30:00 is not equal to either 18:29:59.999 or 18:30:00.001.
So if your datetimes (e.g. 04/25/2019 15:00) start in AF47 and are incremented every thirty minutes then the furthest cell you need to examine is AF95 (47 + 24*2).
With Prediction Area in AF46 and and Model in AG46 this is my effort.
' |<----------AG47:AG95---------->| |<----------AF47:AF95---------->| |<----AF47---->| |<----AF47---->|
=AVERAGEIFS(INDEX(AG:AG, 47):INDEX(AG:AG, 95), INDEX(AF:AF, 47):INDEX(AF:AF, 95), ">"&INT(INDEX(AF:AF, 47))+TIME(18, 29, 59)-(MOD(INDEX(AF:AF, 47), 1)<TIME(18, 30, 1)))
Truth be told, the AVERAGEIFS function does suffer significantly by using full column references so if there are no rogue values that could produce false positives above or below the ranges referenced, full column references could be used for the average_range and criteria1_range cell range references. Full column references would not be affected by row/data insertion.
I have been trying to round a cell value up or down to the nearest thousand but can't get it to work. I'm trying to calculate my hourly rate based on the current exchange rate from USD to VND But if the resulting total is something like 22,325 then it should round down to 22,000 and likewise if the hundreds are 500 or more it should round up to 23,000
So where the hourly rate says 527,325 it should round down to 527,000. The cell already contains a formula to multiply the the current exchange rate by the USD.
Using the ROUND function:
=ROUND(A1,-3)
Where A1 is the cell containing the number you wish to round.
The negative number specifies digits to the left of the decimal point to replace with zeros (the number of zeros at the end of the number).
Like so:
=ROUND( 34528, -3 ) = 35000
As for the OP's example:
=ROUND( 22325, -3 ) = 22000
The OP also stated:
likewise if the hundreds are 500 or more it should round up to 23,000
=ROUND( 22500, -3 ) = 23000
See ROUND Function Office support
You can also try this:
=MROUND(A1,1000)
This should give you what you want.
You've asked specifically for a formula that when it 'says 527,325 it should round down to 527,000'. For this you would need the FLOOR¹ function or ROUNDDOWN¹ function.
=FLOOR(A1, 1000)
=ROUNDDOWN(A1, -3)
There is also leaving the number alone but formatting with a custom number format of 0, K but this does not round down. If the number was 527,501 it would display 528 K not 527 K.
¹ The counterparts to FLOOR and ROUNDDOWN are the CEILING function and ROUNDUP function.
Divide by 1000, then round, then multiply by 1000.
The formula for rounding A1 in this way would be:
=ROUND(A1/1000)*1000
If a formula already exists in the A1 cell, just replace the A1 with the new formula in the upper expression.
Column A Column B
13-06-2013 10:50
13-06-2013 11:30
13-06-2013 12:40
14-06-2013 10:30
I need to find the values which are before a particular entry date and time.
For example, say I want to find the values in the example table above that are immediately prior to the values "13-06-2013" and "12:30".
Since 12:30 is not in column B, how do I find the values I am looking for? The answer should be 13-06-2013 and 11:30.
C7 =VLOOKUP(A7&B7,A1:C4,3,TRUE)
Here A1 = B1&C1
A B C
1 414380.451388888888889 13-06-2013 10:50
2 414380.479166666666667 13-06-2013 11:30
3 414380.527777777777778 13-06-2013 12:40
4 414390.4375 14-06-2013 10:30
5
6 Enter date Enter Time Returned Time
7 13-06-2013 12:30 11:30:00
Setting 'range_lookup' as 'True' adds the flexibility to return the closest approximate value if the exact value is not available.
I think you're looking for something like this. using index and match.
I didn't take into account the date for now. but this gives you an example.
You can compare date strings with operators like > or < etc. Concatenate your values in columns A & B, compare to the desired date/time string. In cell C1 put the following formula, and then drag down:
="13-06-2013 12:30"<A1&" "&B1
or more specifically, depending on which "12:30" you want (AM or PM), ="13-06-2013 12:30AM" or ="13-06-2013 12:30PM"
Your data in column B may default to AM unless otherwise specified/imported differently, so you may need to tweak the data or to account for this.
Here is another approach to answering your question that uses a combination of MATCH, INDEX, and array operations to provide a compact formula solution that does not rely on helper columns.
I'll assume that your two columns of dates and times are in cells A2:B5, and the two date and time values that you want to look up are in cells A9:A10. Then the following two formulas will return what you require, the latest date and time values in your data that are less than or equal to the date and time that you are looking up. (The dollar signs in the formulas are hard on the eyes, but they are important if you will need to copy the formulas to other locations; for clarity, I omit them in the discussion that follows.)
DATE: =INDEX($A$2:$B$5,MATCH(A9+A10,$A$2:$A$5+$B$2:$B$5,1),1) --> 13-06-2013
TIME: =INDEX($A$2:$B$5,MATCH(A9+A10,$A$2:$A$5+$B$2:$B$5,1),2) --> 11:30 AM
These are array formulas and need to be entered with the Control-Shift-Enter key combination. (Of course, only the bits starting with the equal (=) sign and ending with the last parenthesis need to be entered into the worksheet.)
Things to consider:
The formulas assume that your data are valid Excel date and time values. Excel date values are whole numbers that count the number of days that have elapsed since January 1, 1900; Excel time values are decimal amounts between 0 and 1 that represent the fraction of 24 hours that a particular time represents. While your example data don't display AM or PM, I assume that their underlying values do have that information.
If your values are text (having been imported from another source, for instance), you should convert them to date/time values, if lucky, using only Excel's DATEVALUE and TIMEVALUE functions; if not so lucky, using some combination of Excel's string manipulation functions as well. (The values could be kept as strings, but you would almost certainly need to massage them so they would compare correctly "alphabetically" - much easier just to deal with Excel date/time values.)
If they are not already, your dates and times will need to be sorted from smallest to largest. (Your sample looks like they are sorted, and the formulas assume as much.)
How the formulas work
The basic idea behind the formulas is two-fold: first find the row in your data that holds the latest (largest) date and time that is still less than or equal to the date and time you are looking up. That row information can then be used to fetch the final result from each column of the data range (one for date and one for time).
Since both date and time figure in to what point in time is latest, the date and time components of both the value to be looked up and the values that will be searched must be combined somehow.
This can be achieved by simply adding the dates and times together. This does nothing more than what Excel does: an Excel date/time value has an integer part (the number of days since 1/1/1900) and a decimal part (the fraction of 24 hours that a particular time represents).
What is neat here is that the adding up of the dates and times - and the lookup of the particular date and time - can be done all at once, on the fly.
Take a look at the MATCH: The cells that contain the date and time to be looked up - A9 and A10 - are added together, and then this sum is matched against the sum of the date column (A2:A5) and the time column (B2:B5) - an operation that is possible of Excel's array arithmetic capabilities. The match returns a value of 2, indicating correctly that the date and time that fill your requirements are in row 2 of the data table.
DATE/TIME MATCH: = MATCH( A9+A10, A2:A5 + B2:B5, 1 ) --> 2
The 1 that is the final argument to the MATCH function is an instruction that the match results be calculated to be less than or equal to the value to be looked. It is the default value and is often omitted, or replaced with another value (for example, using a value of 0 will produce an exact match, if there is one).
(For readability, I've removed the dollar signs that are in the full formula; these anchor a range so that it remains the same even if the formula is copied to another location.)
Having figured out the row to look in, the rest of the formula is straightforward. The INDEX function returns the value in a data range that is at the intersection of a specified row and column. So, for the date in question, the formula reduces to:
DATE FETCH: = INDEX( A2:B5, 2, 1) --> 13-06-2013
In other words, INDEX is to return the value in the second row and first column of the data range A2:B5.
The formula for the time proceeds in exactly the same fashion, with the only difference that the value is returned from the second column of the data range.