Monday 29 July 2013

SSRS Formatting Expressions

 All formatting options described will be available for download on a .pdf in the next few weeks at the new site.

After working for years with other reporting products I made the move to SSRS and found that one of the more difficult learning curves was to find formatting codes I began with what I thought was a rather simplistic report that contained a simple tabular report with only a few columns. I had no problem with grouping my data, creating the expressions for the footers and headers, or even creating default values for parameters, but hit a wall when I began trying to format my dates and numbers. After finally finding the Format property I was at a loss of what to put in it. The below are the formatting codes that I have compiled since that day:
Date/Time Formatting Codes

 

Date Format Codes


Description

Example
        dShort date 3/12/2006
       DLong date Monday, June 1,2006
       tShort time7:12 PM
       TLong time  6:15:55 AM
       fLong date/short timeMonday, June 1,2006 7:12 PM
       FLong date/long time 
       gShort date/short time 3/12/200619:12
       GShort date/long time 3/12/200619:12
       M or mMonth and day only5-Nov
       Y or yMonth and year onlyOctober, 2002
       YyyyFour digit year2008
       yyTwo digit year8
       MMMMFull month nameApril
       MMM Three character monthJan
       MMOne or two digit month4
       DdddFull day nameFriday
       DddThree character abbrev.Sat
       ddTwo digit day always4
       dOne or two digit day 4
       hhTwo digit hour always 12 hr clk8
       hOne digit hour 12 hr clk8
       HHTwo digit hour always 24 hr clk20
       HOne or two digit hour 24 hr clk8
       MmTwo digit minutes 24
       ssTwo digit seconds24
       ttTwo character AM or PM AM
       tOne character AM or PM 24 hr clk    A
 
NUMERIC FORMAT CODES


Numeric Format Codes


Description


Example
#Optional place holder                                                          
0Required number placehoolder 
%Percentage .95 becomes 95%                                                          
CTwo digit numbers & local currency char$12,345.95(For US currency)
D or D2Decimal value, optionally can specify precision56.95
E or E12Specific notation, optionally can specify precision1.23E+08
P or P1Percentage, optionally can specify precision 87.4
N or N#Numeric, including thousands comma separator prec.Optional1,000
 

Now that you have these formatting codes where exactly do they go?  From within Business Intelligence Development Studio you can right click on the textbox or group and choose Propertiesand from the properties window select the Format tab :
 
or click on the object and browse to the format property in the Properties pane
and enter the formatting code.
 
 
The results for numeric formatting are:

Format
Value
Formatted Value
N010000.0010,000
N110000.0010,000.0
C10000.00$10,000.00
D210000.0010000
P110000.001,000,000.0%
E10000.001.000000E+004
 
The results for date/time formatting are:

Format
Value
Formatted Value
d2/3/2010 12:30.000AM2/3/2010 12:30:00AM
D2/3/2010 12:30.000AMWednesday, February03, 2010
t2/3/2010 12:30.000AM12:30 AM
T2/3/2010 12:30.000AM12:30:00 AM
f2/3/2010 12:30.000AMWednesday, February03, 2010 12:30:00 AM
F2/3/2010 12:30.000AMWednesday, February03, 2010 12:30 AM
g2/3/2010 12:30.000AM2/3/2010 12:30 AM
G2/3/2010 12:30.000AM2/3/2010 12:30:00AM
M or m2/3/2010 12:30.000AMFebruary 03
Y or y2/3/2010 12:30.000AMFebruary, 2010
Yyyy2/3/2010 12:30.000AM2010
This post covered simplistic out of the box formatting and will be followed by more complex formatting of numeric, data/time, and string types, until then you can also refer to MSDN on line documentation:
 

No comments: