SSRS - Converting a value into a number causing issues when working with a NULL value The Next CEO of Stack OverflowSSRS dynamic group expression needs to be null if a parameter is nullSSRS - Inserting Next Row's Value into a Previous RowSSRS- Complex Iff statements in changing background colorssrs not keeping format when exported to excelSSRS IIF expression with TimeSSRS IIF Statement showing #Error when value is non numericSSRS doesn't color the cell when no data (IsNothing)SSRS - Average of periods with valuesexclude nulls in column SSRSSSRS Issue with values that are text and number exporting into excel
Is the D&D universe the same as the Forgotten Realms universe?
Are police here, aren't itthey?
A Man With a Stainless Steel Endoskeleton (like The Terminator) Fighting Cloaked Aliens Only He Can See
If the heap is zero-initialized for security, then why is the stack merely uninitialized?
Why is information "lost" when it got into a black hole?
Domestic-to-international connection at Orlando (MCO)
Flying from Cape Town to England and return to another province
RigExpert AA-35 - Interpreting The Information
Is there a difference between "Fahrstuhl" and "Aufzug"
0-rank tensor vs vector in 1D
Which one is the true statement?
Rotate a column
Do I need to write [sic] when a number is less than 10 but isn't written out?
Unclear about dynamic binding
Is micro rebar a better way to reinforce concrete than rebar?
What is meant by "large scale tonal organization?"
Is wanting to ask what to write an indication that you need to change your story?
Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?
Prepend last line of stdin to entire stdin
Is it my responsibility to learn a new technology in my own time my employer wants to implement?
Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?
Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis
Why do remote US companies require working in the US?
Recycling old answers
SSRS - Converting a value into a number causing issues when working with a NULL value
The Next CEO of Stack OverflowSSRS dynamic group expression needs to be null if a parameter is nullSSRS - Inserting Next Row's Value into a Previous RowSSRS- Complex Iff statements in changing background colorssrs not keeping format when exported to excelSSRS IIF expression with TimeSSRS IIF Statement showing #Error when value is non numericSSRS doesn't color the cell when no data (IsNothing)SSRS - Average of periods with valuesexclude nulls in column SSRSSSRS Issue with values that are text and number exporting into excel
I have an expression in SSRS that is designed to change the format of a field depending on the value of another field:
=IIF(ISNOTHING(Fields!RD.Value), "", IIF(InStr(Fields!ReportHeader_f2.Value,"Average") > 0,Format(Fields!RD.Value,"N") * 1.000,Format(Fields!RD.Value,"#,##;(#,##)") * 1.000))
I need the values to turn up as numbers in the excel spread sheet so I multiply them by 1.000 (I have also tried Cdbl).
When the expression encounters a NULL
value for RD
, the #Error
cell pops up. I've tried using the ISNOTHING()
tag to account for it and I've tried turning the NULL
values into zeroes and then accounting for that.
What could be wrong with my expression?
sql reporting-services
add a comment |
I have an expression in SSRS that is designed to change the format of a field depending on the value of another field:
=IIF(ISNOTHING(Fields!RD.Value), "", IIF(InStr(Fields!ReportHeader_f2.Value,"Average") > 0,Format(Fields!RD.Value,"N") * 1.000,Format(Fields!RD.Value,"#,##;(#,##)") * 1.000))
I need the values to turn up as numbers in the excel spread sheet so I multiply them by 1.000 (I have also tried Cdbl).
When the expression encounters a NULL
value for RD
, the #Error
cell pops up. I've tried using the ISNOTHING()
tag to account for it and I've tried turning the NULL
values into zeroes and then accounting for that.
What could be wrong with my expression?
sql reporting-services
Have you tried in the first condition to look for blank as well?ISNOTHING(Fields!RD.Value) OR Fields!RD.Value = ""
– WEI_DBA
Mar 7 at 17:22
Thanks for reaching back, Wei. I just tried this - this didn't work for me either.
– Scott S.
Mar 7 at 19:08
add a comment |
I have an expression in SSRS that is designed to change the format of a field depending on the value of another field:
=IIF(ISNOTHING(Fields!RD.Value), "", IIF(InStr(Fields!ReportHeader_f2.Value,"Average") > 0,Format(Fields!RD.Value,"N") * 1.000,Format(Fields!RD.Value,"#,##;(#,##)") * 1.000))
I need the values to turn up as numbers in the excel spread sheet so I multiply them by 1.000 (I have also tried Cdbl).
When the expression encounters a NULL
value for RD
, the #Error
cell pops up. I've tried using the ISNOTHING()
tag to account for it and I've tried turning the NULL
values into zeroes and then accounting for that.
What could be wrong with my expression?
sql reporting-services
I have an expression in SSRS that is designed to change the format of a field depending on the value of another field:
=IIF(ISNOTHING(Fields!RD.Value), "", IIF(InStr(Fields!ReportHeader_f2.Value,"Average") > 0,Format(Fields!RD.Value,"N") * 1.000,Format(Fields!RD.Value,"#,##;(#,##)") * 1.000))
I need the values to turn up as numbers in the excel spread sheet so I multiply them by 1.000 (I have also tried Cdbl).
When the expression encounters a NULL
value for RD
, the #Error
cell pops up. I've tried using the ISNOTHING()
tag to account for it and I've tried turning the NULL
values into zeroes and then accounting for that.
What could be wrong with my expression?
sql reporting-services
sql reporting-services
edited Mar 7 at 17:24
iamdave
8,18321439
8,18321439
asked Mar 7 at 16:59
Scott S. Scott S.
66119
66119
Have you tried in the first condition to look for blank as well?ISNOTHING(Fields!RD.Value) OR Fields!RD.Value = ""
– WEI_DBA
Mar 7 at 17:22
Thanks for reaching back, Wei. I just tried this - this didn't work for me either.
– Scott S.
Mar 7 at 19:08
add a comment |
Have you tried in the first condition to look for blank as well?ISNOTHING(Fields!RD.Value) OR Fields!RD.Value = ""
– WEI_DBA
Mar 7 at 17:22
Thanks for reaching back, Wei. I just tried this - this didn't work for me either.
– Scott S.
Mar 7 at 19:08
Have you tried in the first condition to look for blank as well?
ISNOTHING(Fields!RD.Value) OR Fields!RD.Value = ""
– WEI_DBA
Mar 7 at 17:22
Have you tried in the first condition to look for blank as well?
ISNOTHING(Fields!RD.Value) OR Fields!RD.Value = ""
– WEI_DBA
Mar 7 at 17:22
Thanks for reaching back, Wei. I just tried this - this didn't work for me either.
– Scott S.
Mar 7 at 19:08
Thanks for reaching back, Wei. I just tried this - this didn't work for me either.
– Scott S.
Mar 7 at 19:08
add a comment |
3 Answers
3
active
oldest
votes
To me it looks like your IsNothing
isn't catching NULL
values and the error arises when SSRS tries to format the NULL
value but doesn't have a way to handle that. Personally, my preferred solution to this would be to make sure any NULL
values are converted to zeroes in the query/proc prior to coming into the report. Just slap an ISNULL(RD, 0)
and try to handle the zero in the report. I'd also try to CDbl
basically everything coming into this expression just to be sure nothing is coming in with a wrong datatype. Probably a better option than trying to multiply each by 1.000. Additionally, the error could come from trying to multiply the formatted field by 1.000.
SSRS works in mysterious ways. I would think this should work.
=IIF(CDbl(Fields!RD.Value) = 0.0,
"",
IIF(InStr(Fields!ReportHeader_f2.Value, "Average") > 0,
Format(CDbl(Fields!RD.Value), "N"),
Format(CDbl(Fields!RD.Value), "#,##;(#,##)")))
You might also be able to replace the CDbl
conversions with Format(Fields!RD.Value * 1.000, "N")
, etc... There's a few places things could've gone wrong, but this approach seems the most likely to work, IMO.
Another potential solution I explored with my testing was to create a calculated field based on the original field. For example, call it RD2
and set the value equal to =IIF(Fields!RD.Value Is Nothing OR Fields!RD.Value = 0, 0, Fields!RD.Value)
. Then you can use the expression above with the RD2
calculated field. Seemed to catch the zero values in my testing.
That did it! I had the column return zero on IsNull in the SQL and used your SSRS snippet. I did have to add another parenthesis to the end. If you edit your solution to include the extra parenthesis, I'll mark it as the solution. Thank you for your time, Steve-o!! EDIT: Spoke too soon -- the values don't seem to be returning as numbers in the excel sheet. I'll need to investigate on this...
– Scott S.
Mar 7 at 20:18
Done. Happy to assist.
– Steve-o169
Mar 7 at 20:20
@ScottS. Was too late to edit my comment but I'm wondering if theFormat
in some cases changes the value to a string... Not really sure, but you may be better off just bringing the value over and using Excel to format the value accordingly.
– Steve-o169
Mar 7 at 20:26
I figured out what it was. It was the Format line with the "#,##;...etc" piece. SSRS doesn't appear to like when you multiply a string with a double. Client might not like the omission of the comma but I think they would prefer the number format. I'm still going to mark your answer, Steve-o...it led me to what eventually worked: =IIF(CDbl(Fields!RD.Value) = 0.0, "", IIF(InStr(Fields!ReportHeader_f2.Value, "Average") > 0, Format(CDbl(Fields!RD.Value), "N") * 1.000, Format(CDbl(Round(Fields!RD.Value)), "N") * 1.000))
– Scott S.
Mar 7 at 20:31
@ScottS. Can you just do the multiplication before you format? LikeFormat(CDbl(Round(Fields!RD.Value *1.000)), "#,##;(#,##)")
?
– Steve-o169
Mar 7 at 20:35
|
show 2 more comments
1- You can use ISNOTHING function:
=IIF(IsNothing(Fields!RD.Value),0,Fields!RD.Value)
2- Develop a custom query. Open Report menu->Report Properties->Code, and use:
Function IfNullUseZero(myvalue as object)
IF IsNull(myvalue) then
Return 0
Elseif myvalue =" " then
Return 0
End If
then, on the report, do =Code.IfNullUseZero(Fields!RD.Value)
.
Ref: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/bd6dfd75-feb6-4093-8909-6c4054b64c96/convert-null-to-0-in-ssrs?forum=sqlreportingservices
Thanks for reaching back, Eray. When I try the code you pasted, I'm getting an error in the preview screen: 'IsNull' is not declared. It may be inaccessible due to its protection level. Any idea what that might be about?
– Scott S.
Mar 7 at 19:20
@ScottS. can you try: if isnothing(myvalue) then ....
– Eray Balkanli
Mar 7 at 19:34
Tried that. No error message but it didn't resolve the initial problem.
– Scott S.
Mar 7 at 19:43
add a comment |
There are a couple of things happening here causing problems:
Firstly, IIF
is a function not a language construct. This means there is no logic short-circuit depending on the value of the first parameter comparison, it evaluates all parameters before calling the function. So if either the True or False parameter would have an error, the whole thing will blow up regardless of the value of the conditional.
To prevent this you generally need to arrange two IIF
function calls in a way that no error will be encountered. Now to the source of your problem: CDbl
will throw an error if it encounters non-numeric input. The answer by @Steve-o169 prevents this by using two IIF
functions in a way so that no invalid conversion is done, preventing the error. Another way would be to use the Val
function rather than CDbl
because the Val
function does numeric evaluations without throwing an error - it just grabs what it can and calls that a number.
However, you don't actually need to worry about this because presentation should be separate from data: you want the Value
to be numeric, otherwise if you use the Format
function then exporting to Excel will have text values rather than numeric. Rather than put the formating in the Value
expression you should put it in the Format
property where it belongs, so the values will export as numbers and the format will also be correct in Excel.
So we don't even have to worry about the value of the field, just set the expression of the Value
property to the field value so it will export as a number.
Now to set the Format
correctly, in the Format
property of your cell use the following expression:
=IIF(InStr(Fields!ReportHeader_f2.Value, "Average") > 0, "N", "#,##;(#,##)")
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55049176%2fssrs-converting-a-value-into-a-number-causing-issues-when-working-with-a-null%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
To me it looks like your IsNothing
isn't catching NULL
values and the error arises when SSRS tries to format the NULL
value but doesn't have a way to handle that. Personally, my preferred solution to this would be to make sure any NULL
values are converted to zeroes in the query/proc prior to coming into the report. Just slap an ISNULL(RD, 0)
and try to handle the zero in the report. I'd also try to CDbl
basically everything coming into this expression just to be sure nothing is coming in with a wrong datatype. Probably a better option than trying to multiply each by 1.000. Additionally, the error could come from trying to multiply the formatted field by 1.000.
SSRS works in mysterious ways. I would think this should work.
=IIF(CDbl(Fields!RD.Value) = 0.0,
"",
IIF(InStr(Fields!ReportHeader_f2.Value, "Average") > 0,
Format(CDbl(Fields!RD.Value), "N"),
Format(CDbl(Fields!RD.Value), "#,##;(#,##)")))
You might also be able to replace the CDbl
conversions with Format(Fields!RD.Value * 1.000, "N")
, etc... There's a few places things could've gone wrong, but this approach seems the most likely to work, IMO.
Another potential solution I explored with my testing was to create a calculated field based on the original field. For example, call it RD2
and set the value equal to =IIF(Fields!RD.Value Is Nothing OR Fields!RD.Value = 0, 0, Fields!RD.Value)
. Then you can use the expression above with the RD2
calculated field. Seemed to catch the zero values in my testing.
That did it! I had the column return zero on IsNull in the SQL and used your SSRS snippet. I did have to add another parenthesis to the end. If you edit your solution to include the extra parenthesis, I'll mark it as the solution. Thank you for your time, Steve-o!! EDIT: Spoke too soon -- the values don't seem to be returning as numbers in the excel sheet. I'll need to investigate on this...
– Scott S.
Mar 7 at 20:18
Done. Happy to assist.
– Steve-o169
Mar 7 at 20:20
@ScottS. Was too late to edit my comment but I'm wondering if theFormat
in some cases changes the value to a string... Not really sure, but you may be better off just bringing the value over and using Excel to format the value accordingly.
– Steve-o169
Mar 7 at 20:26
I figured out what it was. It was the Format line with the "#,##;...etc" piece. SSRS doesn't appear to like when you multiply a string with a double. Client might not like the omission of the comma but I think they would prefer the number format. I'm still going to mark your answer, Steve-o...it led me to what eventually worked: =IIF(CDbl(Fields!RD.Value) = 0.0, "", IIF(InStr(Fields!ReportHeader_f2.Value, "Average") > 0, Format(CDbl(Fields!RD.Value), "N") * 1.000, Format(CDbl(Round(Fields!RD.Value)), "N") * 1.000))
– Scott S.
Mar 7 at 20:31
@ScottS. Can you just do the multiplication before you format? LikeFormat(CDbl(Round(Fields!RD.Value *1.000)), "#,##;(#,##)")
?
– Steve-o169
Mar 7 at 20:35
|
show 2 more comments
To me it looks like your IsNothing
isn't catching NULL
values and the error arises when SSRS tries to format the NULL
value but doesn't have a way to handle that. Personally, my preferred solution to this would be to make sure any NULL
values are converted to zeroes in the query/proc prior to coming into the report. Just slap an ISNULL(RD, 0)
and try to handle the zero in the report. I'd also try to CDbl
basically everything coming into this expression just to be sure nothing is coming in with a wrong datatype. Probably a better option than trying to multiply each by 1.000. Additionally, the error could come from trying to multiply the formatted field by 1.000.
SSRS works in mysterious ways. I would think this should work.
=IIF(CDbl(Fields!RD.Value) = 0.0,
"",
IIF(InStr(Fields!ReportHeader_f2.Value, "Average") > 0,
Format(CDbl(Fields!RD.Value), "N"),
Format(CDbl(Fields!RD.Value), "#,##;(#,##)")))
You might also be able to replace the CDbl
conversions with Format(Fields!RD.Value * 1.000, "N")
, etc... There's a few places things could've gone wrong, but this approach seems the most likely to work, IMO.
Another potential solution I explored with my testing was to create a calculated field based on the original field. For example, call it RD2
and set the value equal to =IIF(Fields!RD.Value Is Nothing OR Fields!RD.Value = 0, 0, Fields!RD.Value)
. Then you can use the expression above with the RD2
calculated field. Seemed to catch the zero values in my testing.
That did it! I had the column return zero on IsNull in the SQL and used your SSRS snippet. I did have to add another parenthesis to the end. If you edit your solution to include the extra parenthesis, I'll mark it as the solution. Thank you for your time, Steve-o!! EDIT: Spoke too soon -- the values don't seem to be returning as numbers in the excel sheet. I'll need to investigate on this...
– Scott S.
Mar 7 at 20:18
Done. Happy to assist.
– Steve-o169
Mar 7 at 20:20
@ScottS. Was too late to edit my comment but I'm wondering if theFormat
in some cases changes the value to a string... Not really sure, but you may be better off just bringing the value over and using Excel to format the value accordingly.
– Steve-o169
Mar 7 at 20:26
I figured out what it was. It was the Format line with the "#,##;...etc" piece. SSRS doesn't appear to like when you multiply a string with a double. Client might not like the omission of the comma but I think they would prefer the number format. I'm still going to mark your answer, Steve-o...it led me to what eventually worked: =IIF(CDbl(Fields!RD.Value) = 0.0, "", IIF(InStr(Fields!ReportHeader_f2.Value, "Average") > 0, Format(CDbl(Fields!RD.Value), "N") * 1.000, Format(CDbl(Round(Fields!RD.Value)), "N") * 1.000))
– Scott S.
Mar 7 at 20:31
@ScottS. Can you just do the multiplication before you format? LikeFormat(CDbl(Round(Fields!RD.Value *1.000)), "#,##;(#,##)")
?
– Steve-o169
Mar 7 at 20:35
|
show 2 more comments
To me it looks like your IsNothing
isn't catching NULL
values and the error arises when SSRS tries to format the NULL
value but doesn't have a way to handle that. Personally, my preferred solution to this would be to make sure any NULL
values are converted to zeroes in the query/proc prior to coming into the report. Just slap an ISNULL(RD, 0)
and try to handle the zero in the report. I'd also try to CDbl
basically everything coming into this expression just to be sure nothing is coming in with a wrong datatype. Probably a better option than trying to multiply each by 1.000. Additionally, the error could come from trying to multiply the formatted field by 1.000.
SSRS works in mysterious ways. I would think this should work.
=IIF(CDbl(Fields!RD.Value) = 0.0,
"",
IIF(InStr(Fields!ReportHeader_f2.Value, "Average") > 0,
Format(CDbl(Fields!RD.Value), "N"),
Format(CDbl(Fields!RD.Value), "#,##;(#,##)")))
You might also be able to replace the CDbl
conversions with Format(Fields!RD.Value * 1.000, "N")
, etc... There's a few places things could've gone wrong, but this approach seems the most likely to work, IMO.
Another potential solution I explored with my testing was to create a calculated field based on the original field. For example, call it RD2
and set the value equal to =IIF(Fields!RD.Value Is Nothing OR Fields!RD.Value = 0, 0, Fields!RD.Value)
. Then you can use the expression above with the RD2
calculated field. Seemed to catch the zero values in my testing.
To me it looks like your IsNothing
isn't catching NULL
values and the error arises when SSRS tries to format the NULL
value but doesn't have a way to handle that. Personally, my preferred solution to this would be to make sure any NULL
values are converted to zeroes in the query/proc prior to coming into the report. Just slap an ISNULL(RD, 0)
and try to handle the zero in the report. I'd also try to CDbl
basically everything coming into this expression just to be sure nothing is coming in with a wrong datatype. Probably a better option than trying to multiply each by 1.000. Additionally, the error could come from trying to multiply the formatted field by 1.000.
SSRS works in mysterious ways. I would think this should work.
=IIF(CDbl(Fields!RD.Value) = 0.0,
"",
IIF(InStr(Fields!ReportHeader_f2.Value, "Average") > 0,
Format(CDbl(Fields!RD.Value), "N"),
Format(CDbl(Fields!RD.Value), "#,##;(#,##)")))
You might also be able to replace the CDbl
conversions with Format(Fields!RD.Value * 1.000, "N")
, etc... There's a few places things could've gone wrong, but this approach seems the most likely to work, IMO.
Another potential solution I explored with my testing was to create a calculated field based on the original field. For example, call it RD2
and set the value equal to =IIF(Fields!RD.Value Is Nothing OR Fields!RD.Value = 0, 0, Fields!RD.Value)
. Then you can use the expression above with the RD2
calculated field. Seemed to catch the zero values in my testing.
edited Mar 7 at 20:19
answered Mar 7 at 20:00
Steve-o169Steve-o169
718318
718318
That did it! I had the column return zero on IsNull in the SQL and used your SSRS snippet. I did have to add another parenthesis to the end. If you edit your solution to include the extra parenthesis, I'll mark it as the solution. Thank you for your time, Steve-o!! EDIT: Spoke too soon -- the values don't seem to be returning as numbers in the excel sheet. I'll need to investigate on this...
– Scott S.
Mar 7 at 20:18
Done. Happy to assist.
– Steve-o169
Mar 7 at 20:20
@ScottS. Was too late to edit my comment but I'm wondering if theFormat
in some cases changes the value to a string... Not really sure, but you may be better off just bringing the value over and using Excel to format the value accordingly.
– Steve-o169
Mar 7 at 20:26
I figured out what it was. It was the Format line with the "#,##;...etc" piece. SSRS doesn't appear to like when you multiply a string with a double. Client might not like the omission of the comma but I think they would prefer the number format. I'm still going to mark your answer, Steve-o...it led me to what eventually worked: =IIF(CDbl(Fields!RD.Value) = 0.0, "", IIF(InStr(Fields!ReportHeader_f2.Value, "Average") > 0, Format(CDbl(Fields!RD.Value), "N") * 1.000, Format(CDbl(Round(Fields!RD.Value)), "N") * 1.000))
– Scott S.
Mar 7 at 20:31
@ScottS. Can you just do the multiplication before you format? LikeFormat(CDbl(Round(Fields!RD.Value *1.000)), "#,##;(#,##)")
?
– Steve-o169
Mar 7 at 20:35
|
show 2 more comments
That did it! I had the column return zero on IsNull in the SQL and used your SSRS snippet. I did have to add another parenthesis to the end. If you edit your solution to include the extra parenthesis, I'll mark it as the solution. Thank you for your time, Steve-o!! EDIT: Spoke too soon -- the values don't seem to be returning as numbers in the excel sheet. I'll need to investigate on this...
– Scott S.
Mar 7 at 20:18
Done. Happy to assist.
– Steve-o169
Mar 7 at 20:20
@ScottS. Was too late to edit my comment but I'm wondering if theFormat
in some cases changes the value to a string... Not really sure, but you may be better off just bringing the value over and using Excel to format the value accordingly.
– Steve-o169
Mar 7 at 20:26
I figured out what it was. It was the Format line with the "#,##;...etc" piece. SSRS doesn't appear to like when you multiply a string with a double. Client might not like the omission of the comma but I think they would prefer the number format. I'm still going to mark your answer, Steve-o...it led me to what eventually worked: =IIF(CDbl(Fields!RD.Value) = 0.0, "", IIF(InStr(Fields!ReportHeader_f2.Value, "Average") > 0, Format(CDbl(Fields!RD.Value), "N") * 1.000, Format(CDbl(Round(Fields!RD.Value)), "N") * 1.000))
– Scott S.
Mar 7 at 20:31
@ScottS. Can you just do the multiplication before you format? LikeFormat(CDbl(Round(Fields!RD.Value *1.000)), "#,##;(#,##)")
?
– Steve-o169
Mar 7 at 20:35
That did it! I had the column return zero on IsNull in the SQL and used your SSRS snippet. I did have to add another parenthesis to the end. If you edit your solution to include the extra parenthesis, I'll mark it as the solution. Thank you for your time, Steve-o!! EDIT: Spoke too soon -- the values don't seem to be returning as numbers in the excel sheet. I'll need to investigate on this...
– Scott S.
Mar 7 at 20:18
That did it! I had the column return zero on IsNull in the SQL and used your SSRS snippet. I did have to add another parenthesis to the end. If you edit your solution to include the extra parenthesis, I'll mark it as the solution. Thank you for your time, Steve-o!! EDIT: Spoke too soon -- the values don't seem to be returning as numbers in the excel sheet. I'll need to investigate on this...
– Scott S.
Mar 7 at 20:18
Done. Happy to assist.
– Steve-o169
Mar 7 at 20:20
Done. Happy to assist.
– Steve-o169
Mar 7 at 20:20
@ScottS. Was too late to edit my comment but I'm wondering if the
Format
in some cases changes the value to a string... Not really sure, but you may be better off just bringing the value over and using Excel to format the value accordingly.– Steve-o169
Mar 7 at 20:26
@ScottS. Was too late to edit my comment but I'm wondering if the
Format
in some cases changes the value to a string... Not really sure, but you may be better off just bringing the value over and using Excel to format the value accordingly.– Steve-o169
Mar 7 at 20:26
I figured out what it was. It was the Format line with the "#,##;...etc" piece. SSRS doesn't appear to like when you multiply a string with a double. Client might not like the omission of the comma but I think they would prefer the number format. I'm still going to mark your answer, Steve-o...it led me to what eventually worked: =IIF(CDbl(Fields!RD.Value) = 0.0, "", IIF(InStr(Fields!ReportHeader_f2.Value, "Average") > 0, Format(CDbl(Fields!RD.Value), "N") * 1.000, Format(CDbl(Round(Fields!RD.Value)), "N") * 1.000))
– Scott S.
Mar 7 at 20:31
I figured out what it was. It was the Format line with the "#,##;...etc" piece. SSRS doesn't appear to like when you multiply a string with a double. Client might not like the omission of the comma but I think they would prefer the number format. I'm still going to mark your answer, Steve-o...it led me to what eventually worked: =IIF(CDbl(Fields!RD.Value) = 0.0, "", IIF(InStr(Fields!ReportHeader_f2.Value, "Average") > 0, Format(CDbl(Fields!RD.Value), "N") * 1.000, Format(CDbl(Round(Fields!RD.Value)), "N") * 1.000))
– Scott S.
Mar 7 at 20:31
@ScottS. Can you just do the multiplication before you format? Like
Format(CDbl(Round(Fields!RD.Value *1.000)), "#,##;(#,##)")
?– Steve-o169
Mar 7 at 20:35
@ScottS. Can you just do the multiplication before you format? Like
Format(CDbl(Round(Fields!RD.Value *1.000)), "#,##;(#,##)")
?– Steve-o169
Mar 7 at 20:35
|
show 2 more comments
1- You can use ISNOTHING function:
=IIF(IsNothing(Fields!RD.Value),0,Fields!RD.Value)
2- Develop a custom query. Open Report menu->Report Properties->Code, and use:
Function IfNullUseZero(myvalue as object)
IF IsNull(myvalue) then
Return 0
Elseif myvalue =" " then
Return 0
End If
then, on the report, do =Code.IfNullUseZero(Fields!RD.Value)
.
Ref: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/bd6dfd75-feb6-4093-8909-6c4054b64c96/convert-null-to-0-in-ssrs?forum=sqlreportingservices
Thanks for reaching back, Eray. When I try the code you pasted, I'm getting an error in the preview screen: 'IsNull' is not declared. It may be inaccessible due to its protection level. Any idea what that might be about?
– Scott S.
Mar 7 at 19:20
@ScottS. can you try: if isnothing(myvalue) then ....
– Eray Balkanli
Mar 7 at 19:34
Tried that. No error message but it didn't resolve the initial problem.
– Scott S.
Mar 7 at 19:43
add a comment |
1- You can use ISNOTHING function:
=IIF(IsNothing(Fields!RD.Value),0,Fields!RD.Value)
2- Develop a custom query. Open Report menu->Report Properties->Code, and use:
Function IfNullUseZero(myvalue as object)
IF IsNull(myvalue) then
Return 0
Elseif myvalue =" " then
Return 0
End If
then, on the report, do =Code.IfNullUseZero(Fields!RD.Value)
.
Ref: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/bd6dfd75-feb6-4093-8909-6c4054b64c96/convert-null-to-0-in-ssrs?forum=sqlreportingservices
Thanks for reaching back, Eray. When I try the code you pasted, I'm getting an error in the preview screen: 'IsNull' is not declared. It may be inaccessible due to its protection level. Any idea what that might be about?
– Scott S.
Mar 7 at 19:20
@ScottS. can you try: if isnothing(myvalue) then ....
– Eray Balkanli
Mar 7 at 19:34
Tried that. No error message but it didn't resolve the initial problem.
– Scott S.
Mar 7 at 19:43
add a comment |
1- You can use ISNOTHING function:
=IIF(IsNothing(Fields!RD.Value),0,Fields!RD.Value)
2- Develop a custom query. Open Report menu->Report Properties->Code, and use:
Function IfNullUseZero(myvalue as object)
IF IsNull(myvalue) then
Return 0
Elseif myvalue =" " then
Return 0
End If
then, on the report, do =Code.IfNullUseZero(Fields!RD.Value)
.
Ref: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/bd6dfd75-feb6-4093-8909-6c4054b64c96/convert-null-to-0-in-ssrs?forum=sqlreportingservices
1- You can use ISNOTHING function:
=IIF(IsNothing(Fields!RD.Value),0,Fields!RD.Value)
2- Develop a custom query. Open Report menu->Report Properties->Code, and use:
Function IfNullUseZero(myvalue as object)
IF IsNull(myvalue) then
Return 0
Elseif myvalue =" " then
Return 0
End If
then, on the report, do =Code.IfNullUseZero(Fields!RD.Value)
.
Ref: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/bd6dfd75-feb6-4093-8909-6c4054b64c96/convert-null-to-0-in-ssrs?forum=sqlreportingservices
answered Mar 7 at 17:28
Eray BalkanliEray Balkanli
4,53652347
4,53652347
Thanks for reaching back, Eray. When I try the code you pasted, I'm getting an error in the preview screen: 'IsNull' is not declared. It may be inaccessible due to its protection level. Any idea what that might be about?
– Scott S.
Mar 7 at 19:20
@ScottS. can you try: if isnothing(myvalue) then ....
– Eray Balkanli
Mar 7 at 19:34
Tried that. No error message but it didn't resolve the initial problem.
– Scott S.
Mar 7 at 19:43
add a comment |
Thanks for reaching back, Eray. When I try the code you pasted, I'm getting an error in the preview screen: 'IsNull' is not declared. It may be inaccessible due to its protection level. Any idea what that might be about?
– Scott S.
Mar 7 at 19:20
@ScottS. can you try: if isnothing(myvalue) then ....
– Eray Balkanli
Mar 7 at 19:34
Tried that. No error message but it didn't resolve the initial problem.
– Scott S.
Mar 7 at 19:43
Thanks for reaching back, Eray. When I try the code you pasted, I'm getting an error in the preview screen: 'IsNull' is not declared. It may be inaccessible due to its protection level. Any idea what that might be about?
– Scott S.
Mar 7 at 19:20
Thanks for reaching back, Eray. When I try the code you pasted, I'm getting an error in the preview screen: 'IsNull' is not declared. It may be inaccessible due to its protection level. Any idea what that might be about?
– Scott S.
Mar 7 at 19:20
@ScottS. can you try: if isnothing(myvalue) then ....
– Eray Balkanli
Mar 7 at 19:34
@ScottS. can you try: if isnothing(myvalue) then ....
– Eray Balkanli
Mar 7 at 19:34
Tried that. No error message but it didn't resolve the initial problem.
– Scott S.
Mar 7 at 19:43
Tried that. No error message but it didn't resolve the initial problem.
– Scott S.
Mar 7 at 19:43
add a comment |
There are a couple of things happening here causing problems:
Firstly, IIF
is a function not a language construct. This means there is no logic short-circuit depending on the value of the first parameter comparison, it evaluates all parameters before calling the function. So if either the True or False parameter would have an error, the whole thing will blow up regardless of the value of the conditional.
To prevent this you generally need to arrange two IIF
function calls in a way that no error will be encountered. Now to the source of your problem: CDbl
will throw an error if it encounters non-numeric input. The answer by @Steve-o169 prevents this by using two IIF
functions in a way so that no invalid conversion is done, preventing the error. Another way would be to use the Val
function rather than CDbl
because the Val
function does numeric evaluations without throwing an error - it just grabs what it can and calls that a number.
However, you don't actually need to worry about this because presentation should be separate from data: you want the Value
to be numeric, otherwise if you use the Format
function then exporting to Excel will have text values rather than numeric. Rather than put the formating in the Value
expression you should put it in the Format
property where it belongs, so the values will export as numbers and the format will also be correct in Excel.
So we don't even have to worry about the value of the field, just set the expression of the Value
property to the field value so it will export as a number.
Now to set the Format
correctly, in the Format
property of your cell use the following expression:
=IIF(InStr(Fields!ReportHeader_f2.Value, "Average") > 0, "N", "#,##;(#,##)")
add a comment |
There are a couple of things happening here causing problems:
Firstly, IIF
is a function not a language construct. This means there is no logic short-circuit depending on the value of the first parameter comparison, it evaluates all parameters before calling the function. So if either the True or False parameter would have an error, the whole thing will blow up regardless of the value of the conditional.
To prevent this you generally need to arrange two IIF
function calls in a way that no error will be encountered. Now to the source of your problem: CDbl
will throw an error if it encounters non-numeric input. The answer by @Steve-o169 prevents this by using two IIF
functions in a way so that no invalid conversion is done, preventing the error. Another way would be to use the Val
function rather than CDbl
because the Val
function does numeric evaluations without throwing an error - it just grabs what it can and calls that a number.
However, you don't actually need to worry about this because presentation should be separate from data: you want the Value
to be numeric, otherwise if you use the Format
function then exporting to Excel will have text values rather than numeric. Rather than put the formating in the Value
expression you should put it in the Format
property where it belongs, so the values will export as numbers and the format will also be correct in Excel.
So we don't even have to worry about the value of the field, just set the expression of the Value
property to the field value so it will export as a number.
Now to set the Format
correctly, in the Format
property of your cell use the following expression:
=IIF(InStr(Fields!ReportHeader_f2.Value, "Average") > 0, "N", "#,##;(#,##)")
add a comment |
There are a couple of things happening here causing problems:
Firstly, IIF
is a function not a language construct. This means there is no logic short-circuit depending on the value of the first parameter comparison, it evaluates all parameters before calling the function. So if either the True or False parameter would have an error, the whole thing will blow up regardless of the value of the conditional.
To prevent this you generally need to arrange two IIF
function calls in a way that no error will be encountered. Now to the source of your problem: CDbl
will throw an error if it encounters non-numeric input. The answer by @Steve-o169 prevents this by using two IIF
functions in a way so that no invalid conversion is done, preventing the error. Another way would be to use the Val
function rather than CDbl
because the Val
function does numeric evaluations without throwing an error - it just grabs what it can and calls that a number.
However, you don't actually need to worry about this because presentation should be separate from data: you want the Value
to be numeric, otherwise if you use the Format
function then exporting to Excel will have text values rather than numeric. Rather than put the formating in the Value
expression you should put it in the Format
property where it belongs, so the values will export as numbers and the format will also be correct in Excel.
So we don't even have to worry about the value of the field, just set the expression of the Value
property to the field value so it will export as a number.
Now to set the Format
correctly, in the Format
property of your cell use the following expression:
=IIF(InStr(Fields!ReportHeader_f2.Value, "Average") > 0, "N", "#,##;(#,##)")
There are a couple of things happening here causing problems:
Firstly, IIF
is a function not a language construct. This means there is no logic short-circuit depending on the value of the first parameter comparison, it evaluates all parameters before calling the function. So if either the True or False parameter would have an error, the whole thing will blow up regardless of the value of the conditional.
To prevent this you generally need to arrange two IIF
function calls in a way that no error will be encountered. Now to the source of your problem: CDbl
will throw an error if it encounters non-numeric input. The answer by @Steve-o169 prevents this by using two IIF
functions in a way so that no invalid conversion is done, preventing the error. Another way would be to use the Val
function rather than CDbl
because the Val
function does numeric evaluations without throwing an error - it just grabs what it can and calls that a number.
However, you don't actually need to worry about this because presentation should be separate from data: you want the Value
to be numeric, otherwise if you use the Format
function then exporting to Excel will have text values rather than numeric. Rather than put the formating in the Value
expression you should put it in the Format
property where it belongs, so the values will export as numbers and the format will also be correct in Excel.
So we don't even have to worry about the value of the field, just set the expression of the Value
property to the field value so it will export as a number.
Now to set the Format
correctly, in the Format
property of your cell use the following expression:
=IIF(InStr(Fields!ReportHeader_f2.Value, "Average") > 0, "N", "#,##;(#,##)")
answered Mar 14 at 3:52
Chris LattaChris Latta
17.3k45063
17.3k45063
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55049176%2fssrs-converting-a-value-into-a-number-causing-issues-when-working-with-a-null%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you tried in the first condition to look for blank as well?
ISNOTHING(Fields!RD.Value) OR Fields!RD.Value = ""
– WEI_DBA
Mar 7 at 17:22
Thanks for reaching back, Wei. I just tried this - this didn't work for me either.
– Scott S.
Mar 7 at 19:08