I need a ROUND calculation to always round up when it lands between 0 and 1 (but not when it's a value above these numbers), but can't seem to figure out how to make it work.
This is what I have currently:
=ROUND(100/DATA!H6)
try:
=IF((100/DATA!H6>0)*(100/DATA!H6<1), ROUNDUP(100/DATA!H6, ), 100/DATA!H6)
Related
Let's say I have a simple measure like this:
SimpleMeasure = MyTable[Column1]/MyTable[Column2]
Is it possible to have the number of displayed decimals dependent on the value? For example, if my measure calculates the number 500, then I don't want to see 500.00 but rather 500. However if my measure calculates 0.56, then I want to see the value displayed like that to two decimal places and not rounded to the number 1.
So a possible visualization table would look like this:
Store SimpleMeasure
00 10
01 18
02 0.67
03 6
Thank you in advance!
IF(
[SimpleMeasure] < 1, FORMAT([SimpleMeasure], "#,##0.##",
FORMAT([SimpleMeasure], "#,##0")
)
You can use the Switch() function. It will return the first True result. Put you values in a DESC order - start with the largest value, then come to a lower and then to the lowerest. For example :
Switch(
True
,[SimpleMeasure]<1,Round([SimpleMeasure],2) -- 0.655->0.66
,[SimpleMeasure]>999,Round([SimpleMeasure],-2) --1044->1000
,[SimpleMeasure]>499,Round([SimpleMeasure],-1) -- 505,5->510
,[SimpleMeasure]>99,Round([SimpleMeasure],0) -- 101,55->102
,[SimpleMeasure]>1,Round([SimpleMeasure],1) -- 99,43->99.4
)
Or/and you can use in the Switch() the Format() function, with or instead of Round() like:
Format([SimpleMeasure],"#,##0.#")
Or
Format(Round([SimpleMeasure],1),"#,##0.#")
-- Both of them Format() will return and show 99,43 as 99,4.
-- Placeholer # returns a digit or nothing.
-- Placegholder 0 returns a digit or 0.
Usage of Format() and Round() depends on your task. But for a selective Fomat you will need the Switch().
Hope, the answer will help you solve the case
I am trying to create an IF statement formula in excel that converts minutes to days and hours depending on the amount. Then rounds the value to 1 or 2 decimal points and adds the descriptive text (days, hours, etc) to the end
I have tried the following which converts and adds text but does not round:
=IF(L15>=1440, CONVERT(L15,"min","day") & CONCATENATE(L15," days"),
IF(L15>=60, CONVERT(L15,"min","hr") & CONCATENATE(L15," hours"),
IF(L15<=59, CONVERT(L15,"min","min") & CONCATENATE(L15," mins"))))
I would adjust your formula as follows and based on you wanting to round the final number
=IF(L15>=1440,ROUND(L15/1440,2)&" days",IF(L15>=60,ROUND(L15/60,2)&" hours",ROUND(L15,2)&" minutes"))
the ,2 in the ROUND function tell excel how many decimal places to calculate to. if format is set to general, trailing 0s will not be displayed. If you only want 1 decimal calculation then change the ,2 to ,1.
I'm am exploring methods of giving scores to different datapoints within a dataset. These points come from a mix of numbers and text string attributes looking for certain characteristics, e.g. if Col. A contains more than X number of "|", then give it a 1. If not, it gets a 0 for that category. I also have some that give the point when the value is >X.
I have been trying to do this with =IF, for example, =IF([sheet] = [Text], "1","0").
I can get it to give me 1 or 0, but I am unable to get a point total with sum.
I have tried changing the formatting of the text to both "number", "plain text", and have left it as automatic, but I can't get it to sum. Thoughts? Is there maybe a better way to do this?
FWIW - I'm trying to score based on about 12 factors.
Best,
Alex
The issue here might be that you're having the cell evaluate to either the string "0" or the string "1" rather than the number 0 or the number 1. That would explain why you're seeing the right things but the math isn't coming out right - the cell contents look like numbers, but they're really text, which the summation would then ignore.
One option would be to drop the quotation marks and write something like this:
=IF(condition, 1, 0)
This has the condition evaluate to 1 if it's true and 0 if it's false.
Alternatively, you could write something like this:
=(condition) * 1
This will take the boolean TRUE or FALSE returned by condition and convert it to either the numeric value 1 (true) or the numeric value 0 (false).
the code below gives me 0% for each 20th iteration, instead of the actual percentage I would like it to show.
n=100
for i in range(n):
if i% 20 ==0:
print str(i/n*100) + '%, Progress'
Results:
0%, Progress
0%, Progress
etc.....
I must be missing something really simple. Thank you.
change the division to i/(float)n*100 so that the resulting output will be formatted to decimal points by the python interpreter.
Division automatically rounds down to the nearest integer.
What happens in your code is:
i = 20
n = 100
i/n = 20/100, which becomes 0.
Then (i/n)*100 = 0*100 = 0.
You could solve this by first multiplying i by 100 and then dividing by n:
i*100/n
n=100
for i in range(n):
print(i);
if i% 20 ==0:
print str((float(i)/float(n))*100) + '%, Progress'
for python i/n is an (int)/(int) according to your variable declaration. so ti tries to give an int answer for i/n which is always 0.
In each iteration i/n*100 gets rounded down to the nearest integer (this is how the division operator works on integers in python2).
You could either use explicit casting to float() or execute from __future__ import division beforehand. This would prevent the division operator from rounding down automatically.
Here you can find a detailed description of a similar problem.
I want to generate a list that contains random numbers from -100 to 100. The code I have so far just goes from -50 to 50.
for(int line=0;line<100;line++) //reads individual lines and compares them
{
ofs<<rand()%101 + (-50)<<endl;
}
I would really appreciate it if someone could point me in the right direction!
Change to %201 and +(-100). A little experimentation would have figured this out.
Note that you want values from -100 to +100, which is a range of 200 values, so you'd really want:
rand() % 200 // possible off-by-one error
This will give you 0..199. To get closer to the range you want, subtract 99:
(rand() % 200) - 99
This will give you the range -99..+100. This is closer to what you want.
You should be able to go back now and tweak to get the range you really want.
rand() %201 - 100 works just right