SSRS- Conditional formatting with Percents and numbers - dynamic

In my mind this should be easy.. I have spent a good bit of time trying to get this right
Problem-
I have 1 data set that returns whole numbers as well as percents. What I am looking for is a formatting step to work and add the correct suffix (x100+% when % or nothing)
Here is what I have but don't get consistent results
=iif(Fields!Mid_Size.Value<1,Format(Fields!Mid_Size.Value,"P"),Format(Fields!Mid_Size.Value,"#"))
The raw data looks like:
Alpha Mid-Size
11 49
0.0718954248366013 0.320261437908497
Anyone have any ideas?

Try this:
=iif(Fields!Mid_Size.Value<1,FormatPercent(Fields!Mid_Size.Value,0),Format(Fields!Mid_Size.Value,"#"))
This uses the FormatPercent function. The '0' is for no decimal places; you can set that to however many you want.

Related

RAND() not consistently generating the right length value

I've got the following code in place with the idea being that I need a 30 character random number generated each time the stored procedure is called and the odd thing is that in most cases it works as intended but in other seemingly random cases it will only generate a 28 character random number.
'\\xxx-servername\folder\'+
CAST(CAST((RAND()*1000000000000000000000000000000) as decimal(30))as varchar(30)) +
RAM.AccountNumber+HRMRN.PrefixMedicalRecordNumber+'ESTIMATE N00001'+
REPLACE(CONVERT(VARCHAR(12),ISNULL(HRM.Birthdate,HRM.BirthdateComputed),111),'/','')+HRM.Sex+
REPLACE(CONVERT(VARCHAR(12),GetDate(),111),'/','')+LEFT(REPLACE(CONVERT(VARCHAR(12),GetDate(),108),':',''),4)+'.PDF' as [CPFileName]
Hope maybe someone can offer some advice because I'm at a loss...
I suspect that your system is automatically removing leading zeros. You can either re-insert those zeros yourself, or else construct your number using something like:
number <- ""
number.append(randomDigit(1,9))
repeat 29 times
number.append(randomDigit(0,9))
end repeat
That guarantees that you do not get a leading zero.

Correctly convert price into a 8 digits string on ms-access

I need to convert a price into a string of 8 digits and right now, I'm using this:
=Format(Replace(Round([total],2),",",""),"00000000")
If the price is (eg: 105.55) it converts like this: 00010455 and this is ok!
The problem:
When the price ends with a zero (like this: 147.60). In this case, it returns 00001476and it's missing the last zero which I need to correctly solve the rest.
Even if I remove the Round part, I get the same problem.
=Format(Replace([total],",",""),"00000000")
I can't figure why this is happening and how to do it right...
Try this simpler approach:
=Format([total] * 100, "00000000")

Adding various number of dots in excel

I have a lot of excel files looking like that:
Example:
My goal is to make it look like that:
To do that, I used very simple excel's function:
=F7&" "&G7&".........cat."&" "&H7&" times "&I7&CHAR(10)&F8&" "&G8&".........cat."&" "&H8&" times "&I8&CHAR(10)
The thing is, the number of dots placed before "cat" is not constant. It depends where the previous sentence ends and my formula doesn't take it into account - it always adds 9 dots, which means I have to add the rest of the dots manually.
Any ideas how to make it work? :D
The REPT function can do this. Use LEN to calculate the length of what you're adding the dots to, then subtract that from the desired width of the result. That will repeat the dot enough times to fill the column. For example, if you want the text with dots to be 40 characters, right padded with .:
=F1&" "&G1&REPT(".",40-LEN(G1))&"cat."&" "&H1&" times "&I1&CHAR(10)&F2&""
=LEFT(A1 & REPT(".",22-LEN(A1))&"cat",25)
22 = fixed width - len("cat"), 25 - fixed width.
edit - i revised because my original answer was not correct but I see Comintern has posted a similar response since.

Splitting information from a cell

My sheet contains three types of cells:
5off
50off
550off
What they should read is:
$5.00 Off
$0.50 Off
$5.50 Off
I've been fighting with Text-to-Columns and =concat for a while and am trying to get this to work as easily as possible. Any ideas?
Just wondering what's the rule of the conversion for example the first figure is
5off => "$5.00 Off" > split number, add decimal, upper the O in off, concatenate
However in number two the rules are a little different
50off => "$0.50 Off" > split number, make the number decimal, concatenate
Based on those limited information I will suggest you to break down your problem to simpler form:
See image below, the top is the result, bottom is the formula used. There might be simpler way though.
Hope this help

Formatted output with leading zeros in Fortran

I have some decimal numbers that I need to write to a text file with leading zeros when appropriate. I've done some research on this, and everything I've seen suggests something like:
REAL VALUE
INTEGER IVALUE
IF (VALUE.LT.0) THEN
IVALUE = CEILING(VALUE)
ELSE
IVALUE = FLOOR(VALUE)
ENDIF
WRITE(*,1) IVALUE, ABS(VALUE)-ABS(IVALUE)
1 FORMAT(I3.3,F5.4)
As I understand it, the IF block and ABS parts should allow this to work for all values on -100 < VALUE < 1000. If I set VALUE = 12.3456, the code above should produce "012.3456" as the output, and it does. However if I have something like VALUE = -12.3456, I'm getting "(3 asterisks).3456" as my output. I know the asterisks usually shows up when there are not enough characters provided for in the FORMAT statement, but 3 should be enough in this example (1 character for the "-" and two characters for "12"). I haven't tested this yet with something like VALUE = -9.876, but I'd expect the output to be "-09.8760".
Is there something wrong in my understanding of how this works? Or is there some other limitation of this technique that I'm violating?
UPDATE: Okay I've looked into this some more, and it seems to be a combination of a negative value and the I3.3 format. If VALUE is positive and I have the I3.3, it will put leading zeros as expected. If VALUE is negative and I only have I3 as my format, I get the correct value output, but it will be padded with spaces before the negative sign instead of padded with zeros after the negative (so -9.8765 is output as " -9.8765", but that leading space breaks what I'm using the .txt file for, so it's not acceptable).
Tho problem is with your integer data edit descriptor. With I3.3 you require at least 3 digits and the field width is only 3. There is no place for the minus sign. Use I4.3 or, In Fortran 95 and above, I0.3.
Answer to your edit: Use I0.3, it uses the minimum number of characters necessary.
But finally, you just probably want this: WRITE(*,'(f0.3)') VALUE
Of course, I could get what I'm looking for by changing it up a little bit to
REAL VALUE
INTEGER IVALUE
IF (VALUE.LT.0) THEN
WRITE(*,1) FLOOR(ABS(IVALUE)), ABS(VALUE)-FLOOR(ABS(VALUE))
1 FORMAT('-',I2.2,F5.4)
ELSE
WRITE(*,2) FLOOR(VALUE), ABS(VALUE)-FLOOR(BS(VALUE))
2 FORMAT(I3.3,F5.4)
ENDIF
But this feels a lot clunkier, and in reality I'm going to try to be writing multiple values in the same line, which will lead to really messy IF blocks or complex cursor movement, which I'd like to avoid if at all possible.
as another way to skin the cat.. I'd prefer not to do arithmatic on the data at all but just work on the format:
character*8 fstring/'(f000.4)'/
val=12.34
if(val.gt.1)then
write(fstring(3:5),'(i0)')6+floor(log10(val))
elseif(val.lt.-1)then
write(fstring(3:5),'(i0)')7+floor(log10(-val))
elseif(val.ge.0)
write(fstring(3:5),'(i0)')6
else
write(fstring(3:5),'(i0)')7
endif
write(*,fstring)val
just for fun with modern fortran that supports character functions you can roll that up in a function and end up with a construct like this:
write(*,'('//fstring(val1)//','//fstring(val2)//')')val1,val2