简体   繁体   中英

SSRS expression - Format only when data is present

I have a phone number field in an SSRS report where I have used an expression to put the phone number into the proper format

(FORMAT(VAL(Fields!Home_Phone.Value),"(###)###-####"))

However, when there is no phone number, I am getting ()- as the value for that field. I would like to have the field be completely blank if there is no phone number. I thought the expression below would work, but I am still getting the same result of ()- for missing phone numbers.

=IIF(ISNOTHING(Fields!Home_Phone.Value),nothing,(FORMAT(VAL(Fields!Home_Phone.Value),"(###)###-####")))

Appreciate any guidance I can get.

There are a number of things you can try. My preference would be to right click the text box the phone number sits in, select "Properties", and pick the "Visibility" tab. Set an expression that tests the value of phone number and hides the cell contents if there is no phone number.

If you want to use the IIF test, I'd try testing something other than ISNOTHING, I'd test for a value. I don't have hard proof, but it seems like the ISNOTHING/ISNULL/ISEMPTY tests are finicky and don't always give the results I expect. So try testing a value like

=IIF(Fields!Home_Phone.Value>100,(FORMAT(VAL(Fields!Home_Phone.Value),"(###)###-####")),"")

Note that for this your format type for the text box should be "General" because the formatting is happening before the value is passed to the text box. Also note that it's passing back an empty string, not NOTHING.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM