Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the valid Style Format Strings for a Reporting Services [SSRS] Expression?

I am trying to figure out the style string for the Format(Expression as Object, Style as String) function in a Reporting Services expression.

I can't find where these style format strings are documented!

Specifically I am trying to format a Price field to be always 2 decimal places.

ie 1.5 formats to $1.50

like image 897
Jon Erickson Avatar asked May 28 '09 18:05

Jon Erickson


People also ask

How do you write expressions in SSRS report?

Expressions are a very powerful feature of SSRS. They enable us to show fields at run time depending on conditions. Generally expressions are written in Visual Basic and there are many built-in functions provided. We can have also custom code for expressions.

What is first in SSRS expression?

The First function returns the first value in a set of data after all sorting and filtering have been applied at the specified scope. The First function cannot be used in group filter expressions with anything except the current (default) scope.

What is report expression?

Report expressions are the powerful features of JasperReports, which allow us to display calculated data on a report. Calculated data is the data that is not a static data and is not specifically passed as a report parameter or datasource field.


2 Answers

Format with Currency format string

=Format(Fields!Price.Value, "C") 

It will give you 2 decimal places with "$" prefixed.

You can find other format strings on MSDN: Adding Style and Formatting to a ReportViewer Report

Note: The MSDN article has been archived to the "VS2005_General" document, which is no longer directly accessible online. Here is the excerpt of the formatting strings referenced:

Formatting Numbers

The following table lists common .NET Framework number formatting strings.

Format string, Name

C or c Currency

D or d Decimal

E or e Scientific

F or f Fixed-point

G or g General

N or n Number

P or p Percentage

R or r Round-trip

X or x Hexadecimal

You can modify many of the format strings to include a precision specifier that defines the number of digits to the right of the

decimal point. For example, a formatting string of D0 formats the number so that it has no digits after the decimal point. You

can also use custom formatting strings, for example, #,###.

Formatting Dates

The following table lists common .NET Framework date formatting strings.

Format string, Name

d Short date

D Long date

t Short time

T Long time

f Full date/time (short time)

F Full date/time (long time)

g General date/time (short time)

G General date/time (long time)

M or m Month day

R or r RFC1123 pattern

Y or y Year month

You can also a use custom formatting strings; for example, dd/MM/yy. For more information about .NET Framework formatting strings, see Formatting Types.

like image 76
dance2die Avatar answered Sep 20 '22 17:09

dance2die


As mentioned, you can use:

=Format(Fields!Price.Value, "C") 

A digit after the "C" will specify precision:

=Format(Fields!Price.Value, "C0") =Format(Fields!Price.Value, "C1") 

You can also use Excel-style masks like this:

=Format(Fields!Price.Value, "#,##0.00") 

Haven't tested the last one, but there's the idea. Also works with dates:

=Format(Fields!Date.Value, "yyyy-MM-dd") 
like image 29
Peter Radocchia Avatar answered Sep 18 '22 17:09

Peter Radocchia