format_string in icCube does not format null values - mdx

I was trying to display values that are null as 0 using format_string.
I currently have the following:
WITH
MEMBER [test] AS null, FORMAT_STRING = '0.#;Neg (0.#);0.00;0.00'
SELECT
[test] ON COLUMNS
FROM [Sales]
The fourth value (;0.00) should format the null values to zeros. I read that here: https://msdn.microsoft.com/en-us/library/ms146084.aspx
Currently it shows nothing. It should show 0.00.
You can try it here: http://www.iccube.com/run-mdx

It is a bug (ic3pub_159) that is going to be fixed in the next version. As a workaround you can use the coalesceEmpty MDX function.
CoalesceEmpty( [MyValue] , 0.0 )

Related

How to Multiply using Expression in RDLC ignore if it has string or null values with visual studio 2013

Hi Im having a problem in multiplying the Fields if it is 1 field is string. For ex. Multiplying the Number*String I got #error answer, it should be automatically to 0 but in null values, I have a function correctly and the answer is 0. How to solve my problem?
Here is my code currently function with null values:
=Sum(IIf(Not IsNOthing(Fields!Unit.Value * Fields!Grade.Value), CDbl(Fields!Unit.Value * Fields!Grade.Value), 0)))
I have tried also:
=Sum(IIf(Fields!Unit.Value>0 And Fields!Grade.Value>0, CDbl(Fields!Unit.Value * Fields!Grade.Value), 0))
but the same I got error in multiplying with Number*String.
I've got my screenshot here:

Return Character from Numeric Field using Cast & Coalesce

Using SQL Server 2008 R2
Relatively basic SQL user, apologies if this is a simple question but need a little help to tidy up the output of a fairly complex script I have been given.
I have a number of columns being returned for which where there is a NULL, I want to replace all NULL's with a standard set of characters, currently "---". Using ISNULL works for most columns. However, for some columns we are looking at 2 tables to find a value so have after doing some research on here, I have modified a line I am having trouble with as follows:
Previous
isnull (ff.ff_sales,aa.ff_sales) as 'Total Revenue'
Latest
cast(coalesce(ff.ff_sales,aa.ff_sales,'') as FLOAT) as 'Total Revenue'
The initial line returned 'NULL' if both ff.ff_sales & aa.ff_sales were empty, now with the latest line using cast & coalesce I get '0'. However, I am trying to achieve a situation where I get '---' as per all other fields where a NULL exists. I don't want it to return '0' for a Sales field as this is misleading. I have tried using VARCHAR instead of FLOAT but am unsure if this is the right thing to do at this stage?
1st column is using ISNULL, 2nd column current output with cast & coalesce, 3rd column is what I want to get to:
Total Revenue Total Revenue Total Revenue
67755 67755 67755
6.123 6.123 6.123
494.75 494.75 494.75
0 0 0
1139909 1139909 1139909
12346.45 12346.45 12346.45
129.866 129.866 129.866
NULL 0 ---
NULL 0 ---
554 554 554
Thanks for your help!
You can use case to decide what should be output in this scenario, like so:
select
case
when isnull (ff.ff_sales,aa.ff_sales) is null then '---'
else cast(isnull (ff.ff_sales,aa.ff_sales) as varchar)
end as 'Total Revenue'
This will force the output to be returned as varchar though, because you cannot cast '---' as a numeric type.
Alternatively, you could just let the value be NULL in DB, and in your presentation layer, replace a DBNull or equivalent value with '---'. This will let you keep total revenue as a numeric field at the DB level.

Arithmetic overflow error converting nvarchar to data type numeric when the value is 0

I have the following query returns resulting me Null or Zero:
SELECT TOP 1 ISNULL([jul-12],0) FROM Table_tmp
WHERE ID = 123250838
but when I add a condition asking if the column value is zero causes overflow error:
SELECT TOP 1 ISNULL([jul-12],0) FROM Table_tmp
WHERE ID = 123250838
AND [jul-12] <> 0
The data type of the column is FLOAT
exec sp_help 'Table_tmp'
jun-12 float no 8 53 NULL yes (n/a) (n/a) NULL
I tried with the functions CONVERT () and CAST () but with the same result.
But when the value of the column [Jul-12] is nonzero, it works without errors. Why does this happen?
Try like below... may be it will help you...
SELECT TOP 1 ISNULL([jul-12],0) FROM Table_tmp
WHERE Str([jul-12], 25, 5) <> '0'
This is because of CAST () specification. The result data type will be as in the second parameter. To avoid this you can use COALESCE function which determine result data type by first parameter, also benefit of this function is that it's ANSI standard (instead of ISNULL).
you can look for this function here:
COALESCE MSDN
usage in your case is: COALESCE(jul-12],0) - this will return first not null value.
I just ran across this problem and solved it by throwing an "IS NOT NULL" clause into "WHERE" on the column that I was using cast()

how can I replace blank value with zero in MS-Acess

I have below query in Ms-Access but I want to replace Blank value with zero but I can't get proper answer. Is there any way to replace blank value in zero.
(SELECT
SUM(IIF(Review.TotalPrincipalPayments,0,Review.TotalPrincipalPayments))+
SUM(IIF(Review.TotalInterestPayments,0,Review.TotalInterestPayments ))
FROM
tblReviewScalars as Review
INNER JOIN tblReportVectors AS Report ON(Review.LoanID=Report.LoanID)
WHERE Report.AP_Indicator="A" AND Report.CashFlowDate=#6/5/2011# AND Review.AsofDate=#6/5/2011# AND ( Review.CreditRating =ReviewMain.CreditRating)) AS [Cash Collected During the Period],
I assume TotalPrincipalPayments and TotalInterestPayments are both numeric types, hence the 'blanks' in question is the NULL value.
In SQL, the set function SUM will disregard NULL values, unless all values resolve to NULL in which case NULL is returned (erroneously and the error is with SQL not Access for a change :)
To use a simple example, SELECT SUM(a) FROM T; will only return NULL when a IS NULL is TRUE for all rows of T or when T is empty. Therefore, you can move the 'replace NULL with zero' logic outside of the SUM() function. Noting that "NULLs propagate" in calculations, you will need to handle NULL for each SUM().
You haven't posted the whole of your query e.g. the source of the correlation name ('table alias') ReviewMain is not showm. But it seems clear you are constructing a derived table named "Cash Collected During the Period", in which case your calculated column needs an AS clause ('column alias') such as TotalPayments e.g.
...
(
SELECT IIF(SUM(Review.TotalPrincipalPayments) IS NULL, 0, SUM(Review.TotalPrincipalPayments))
+ IIF(SUM(Review.TotalInterestPayments) IS NULL, 0, SUM(Review.TotalInterestPayments))
AS TotalPayments
FROM tblReviewScalars as Review
INNER JOIN tblReportVectors AS Report
ON Review.LoanID = Report.LoanID
WHERE Report.AP_Indicator = 'A'
AND Report.CashFlowDate = #2011-05-06#
AND Review.AsofDate = #2011-05-06#
AND Review.CreditRating = ReviewMain.CreditRating
) AS [Cash Collected During the Period], ...
An alternative to #onedaywhen's answer is to use the nz function, which is specifically for null-substitution:
SELECT
SUM(NZ(Review.TotalPrincipalPayments,0))+
SUM(NZ(Review.TotalInterestPayments,0))
...
As onedaywhen pointed out, this is functionally equivalent to putting the function outside the aggregate, which may perform better (the function is called once, rather than once per un-aggregated row):
SELECT
NZ(SUM(Review.TotalPrincipalPayments),0)+
NZ(SUM(Review.TotalInterestPayments),0)
...
To change a null value to a zero in an Access 2010 database, open your table, go to design view, click on the field and set the default value to: =0.

SQL-Doesn't return a value when the columns are multiplied

I have 3 columns in my db table, I need to multiply column, itm_count & itm_price and output the total for a given id(itm_id).
SELECT sum(itm_price * itm_count) as total FROM ods_temporder WHERE itm_id='11'
I tried to do this using the above sql query, but the result was null. What seems to be the issue here?
What do this give you?
SELECT itm_price, itm_count FROM ods_temporder WHERE itm_id='11'
Is either of itm_price or itm_count NULL? Do you have rows for itm_id = 11?
Try:
SELECT SUM(COALESCE(itm_price, 0) * COALESCE(itm_count, 0)) as total
FROM ods_temporder
WHERE itm_id='11'
COALESCE is an ANSI standard for dealing with NULL values - if itm_price or itm_count is null, zero will be used in this case as the value. Otherwise, either you don't have a row with a value of 11 for the itm_id column, or you're looking for the 11 value in the wrong column.
What does itm_price and itm_count contain when itm_id= 11?
Is this SQL Server? If so you can use ISNULL to handle whether itm_price or itm_count is null