dbTalk Databases Forums  

Possible to pad a resultset if non existing values?

microsoft.public.sqlserver.olap microsoft.public.sqlserver.olap


Discuss Possible to pad a resultset if non existing values? in the microsoft.public.sqlserver.olap forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Kaisa M. Lindahl
 
Posts: n/a

Default Possible to pad a resultset if non existing values? - 01-18-2006 , 10:04 AM






Is it possible to make a query return 0 for all non existing values?

I've created a query from Foodmart:
with set MonBud as '{[Time].[1997].[Q3].[7]:[Time].[1997].[Q3].[7].lag(3),
[Time].[1998].[Q3].[7]:[Time].[1998].[Q3].[7].lag(3)}'
select
{[Measures].[Store Cost],[Measures].[Store Sales]} on columns,
{MonBud} on rows
from [Sales]

It returns values for 1997, but not for 1998. Is it possible to make it
return 0 instead of Null or Nothing?

All help appreciated!

Kaisa M: Lindahl



Reply With Quote
  #2  
Old   
Deepak Puri
 
Posts: n/a

Default Re: Possible to pad a resultset if non existing values? - 01-18-2006 , 05:39 PM






Hi Kaisa,

If you have AS 2000 Enterprise Edition, try this:

Quote:
with set MonBud as
'{[Time].[1997].[Q3].[7]:[Time].[1997].[Q3].[7].lag(3),
[Time].[1998].[Q3].[7]:[Time].[1998].[Q3].[7].lag(3)}'
Cell Calculation [ForceNull] for '(Measures.AllMembers)'
as '0', CONDITION = 'IsEmpty(CalculationpassValue(
Measures.CurrentMember, -1, RELATIVE))'
select
{[Measures].[Store Cost],[Measures].[Store Sales]} on columns,
{MonBud} on rows
from [Sales]
Quote:

- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***


Reply With Quote
  #3  
Old   
Kaisa M. Lindahl
 
Posts: n/a

Default Re: Possible to pad a resultset if non existing values? - 01-19-2006 , 04:03 AM



I have Standard Edition, but it still worked.
THanks a lot!

Kaisa
"Deepak Puri" <deepak_puri (AT) progressive (DOT) com> wrote

Quote:
Hi Kaisa,

If you have AS 2000 Enterprise Edition, try this:


with set MonBud as
'{[Time].[1997].[Q3].[7]:[Time].[1997].[Q3].[7].lag(3),
[Time].[1998].[Q3].[7]:[Time].[1998].[Q3].[7].lag(3)}'
Cell Calculation [ForceNull] for '(Measures.AllMembers)'
as '0', CONDITION = 'IsEmpty(CalculationpassValue(
Measures.CurrentMember, -1, RELATIVE))'
select
{[Measures].[Store Cost],[Measures].[Store Sales]} on columns,
{MonBud} on rows
from [Sales]



- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***



Reply With Quote
  #4  
Old   
Kaisa M. Lindahl
 
Posts: n/a

Default Re: Possible to pad a resultset if non existing values? - 01-19-2006 , 04:33 AM



What datatype are the padded values?
The query works well against the OLAP cube, I get a string of 0s. But when I
try using the query in a Reporting Services 2000 report, it will just
display #Error. I get an error message saying
The value expression for the textbox 'textbox8' uses an aggregate function
on data of varying data types. Aggregate functions other than First, Last,
Previous, Count, and CountDistinct can only aggregate data of a single data
type.

I'm trying to do a SUM(). How can I make my 0s be the same datatype as the
other numbers?



Kaisa M. Lindahl



"Deepak Puri" <deepak_puri (AT) progressive (DOT) com> wrote

Quote:
Hi Kaisa,

If you have AS 2000 Enterprise Edition, try this:


with set MonBud as
'{[Time].[1997].[Q3].[7]:[Time].[1997].[Q3].[7].lag(3),
[Time].[1998].[Q3].[7]:[Time].[1998].[Q3].[7].lag(3)}'
Cell Calculation [ForceNull] for '(Measures.AllMembers)'
as '0', CONDITION = 'IsEmpty(CalculationpassValue(
Measures.CurrentMember, -1, RELATIVE))'
select
{[Measures].[Store Cost],[Measures].[Store Sales]} on columns,
{MonBud} on rows
from [Sales]



- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***



Reply With Quote
  #5  
Old   
Rose
 
Posts: n/a

Default Re: Possible to pad a resultset if non existing values? - 01-23-2006 , 05:04 AM



I tried it out using Deepak's way on Adventure Works. Besides padding
the (null) values to 0, Deepak's way also changed all the non-zero
values to (null), which was not expected. Is that what it is supposed
to do? [ I am using AS 2005 RTM ]

#1 - no padding
with set MonBud as
'{[Date].[Calendar].[Month].&[2003]&[7]:[Date].[Calendar].[Month].&[2003]&[7].lag(3),

[Date].[Calendar].[Month].&[2004]&[7]:[Date].[Calendar].[Month].&[2004]&[7].lag(3)}'

select {[Measures].[Reseller Freight Cost],[Measures].[Reseller Sales
Amount]} on columns,
{MonBud} on rows
from [Adventure Works]

#2 - padding with 0
with set MonBud as
'{[Date].[Calendar].[Month].&[2003]&[7]:[Date].[Calendar].[Month].&[2003]&[7].lag(3),

[Date].[Calendar].[Month].&[2004]&[7]:[Date].[Calendar].[Month].&[2004]&[7].lag(3)}'

Cell Calculation [ForceNull] for '(Measures.AllMembers)'
as '0', CONDITION =
'IsEmpty(CalculationpassValue(Measures.CurrentMemb er, -1, RELATIVE))'
select {[Measures].[Reseller Freight Cost],[Measures].[Reseller Sales
Amount]} on columns,
{MonBud} on rows
from [Adventure Works]


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.