Friday, August 24, 2012

Left align a number, currency, or percentage column in a SharePoint list.

Sometimes when you're being finicky about how a list appears on SharePoint you might find that you don't like the way it looks when number-type fields are right aligned by default.  This is generally how the fields would look in Excel but that isn't always the best way to display them.

One simple way to fix this is to create a calculated column based on the original column that you'll use in your view.
If you create a calculated column and select "single line of text" as the data format you'll have a left aligned field.  There are a couple things you'll want to keep in mind when using this method.  If there are blanks in your source field the calculated column will show these as a zero.  To avoid this you can change your calculated field to this.
=IF([Source Column]<>"",[Source Column],"")
This will have any blanks appear as blanks, not zeros.

If you're trying to left align a currency field you'll need to add code add the dollar sign back in.
=IF([Source Column]<>"","$" & [Source Column],"")
Percentage is not so straight forward since 23% will be displayed as 0.23 using this method.   If we multiply the number by 100 and attach a percentage symbol we should have a left aligned percentage.
=IF([Source Column]<>"",[Source Column]*100&"%","")

No comments:

Post a Comment