Showing posts with label measures. Show all posts
Showing posts with label measures. Show all posts

Tuesday, March 20, 2012

Nonempty Problem

following query is nt working properly. need a solution (need to filter the non empty rows)

SELECT
{[Measures].[Description],[Measures].[Amount]} ON COLUMNS,
non empty CROSSJOIN ([CustomTimeSet],[GeneralLedgerSet]) on rows

FROM Profitability
WHERE [Account—ETBillingCode].[MDA]NonEmpty({filter(CROSSJOIN([CustomTimeSet],[GeneralLedgerSet]),[Measures].[MdaCodeTotal] <> 0 )})on rows

I am a bit suspicious about the [Measures].[Description] measure. Is this a calculated measure? It could be what is causing the non empty clause not to work. If you are using SSAS 2005, something like the following might work:

SELECT
{[Measures].[Description],[Measures].[Amount]} ON COLUMNS,
nonempty( CROSSJOIN ([CustomTimeSet],[GeneralLedgerSet]) , {Measures.MdaCodeTotal})on rows

FROM Profitability
WHERE [Account—ETBillingCode].[MDA]

Note I am using the second parameter in the NonEmpty() function to set the measure context for the non empty evaluation.

Monday, March 12, 2012

Non-additive measures

We need to support non-additive measures in our cube, such as rates. The rates will be averaged across time by using a custom formula (weighted average). The rate measures cannot be aggregated by any other dimension. However, when the end user browses by the Account dimension (each member in the Account dimension relates to exactly one record in the fact table), the user must be able to see the rates.

I set the average function of the rates measures to None. How can I surface the rate measures from the measure leaves to the Account dimension leaves?

What is the granularity of rates in the fact table ? If they are entered, for example, per Account and Time - you should create new measure group at that granularity.|||

Hi, Mosha. I appologize for not making this clearer. The measure group is already created. The lowest grain is the Account dimension. The measure group intersect with other dimensions too, including Time. Besides non-additive measures, the measure group has additive and semi-additive measures.

If the aggregate function of a measure is None, is it possible to show up that measure at the Account level so I can apply the custom aggregation formula across time to get:

Jan Feb Mar Apr .... Total

Acct A 0.45 0.5 0.6 0.4 = (0.45 * 31 + 0.5 * 28 + 0.6 * 31 + 0.4 * 30 + ...) / Total days for selected months

Acct B 0.30 0.35 0.75 0.8 = <same custom formula>

Again, an Account member has no more than one corresponding record in the measure group always.

|||What I suggested was to leave all other (additive) measures in the measure group that you already created. Based on your example, the granularity of Rates is at least Account and Time (but possibly other attributes). You need to create NEW measure group and include just these two dimensions (unless rates vary by other dimensions as well). You didn't specify how the rates should aggregate across accounts, but probably they don't at all.|||

Thanks Mosha. I prefer to leave the rates in the same measure group for usability reasons and I think I have a workaround by setting the Account All member to NULL and the measure aggregate function to SUM.

Let me ask a more general question. If I have an aggregate function of None, is it possible to bring up the measure leaves to the dimension leaves? I haven't been successful doing so. At the same time, this is what BOL states for the None aggregate function:

"No aggregation is performed, and all values for leaf and nonleaf members in a dimension are supplied directly from the fact table for the measure group that contains the measure."

Why I don't see the non-additive measure values when browsing at the Account leaves then?

|||

I prefer to leave the rates in the same measure group for usability reasons

What are these usability reasons ? By artificially forcing deeper grain on the rates you make your model less natural and it is harder to work with. Why are you so resistant to set correct grain for you rate measures ?

If I have an aggregate function of None, is it possible to bring up the measure leaves to the dimension leaves?

I think you misunderstand the notion of "measure group leaves" and "dimension leaves". Perhaps the following blog will be of help: http://www.sqljunkies.com/WebLog/mosha/archive/2006/04/29/leaves.aspx

Anyway, if you were to follow my advice about creating measure group with Account and Time, and set custom formula to aggregate Time as Average - you wouldn't have had this issue.

|||

What are these usability reasons ? Why are you so resistant to set correct grain for you rate measures ?

B/c the semi-additive and additive measures will be organized in display folders under one measure group while the rates will be under another. If you are building off-the-shelf solution, things like these matter especially when your end users haven't heard about OLAP. Besides, I need to worry now about partitioning and processing a separate measure group.

I think you misunderstand the notion of "measure group leaves" and "dimension leaves". Perhaps the following blog will be of help: http://www.sqljunkies.com/WebLog/mosha/archive/2006/04/29/leaves.aspx

I've read the article (thanks for sharing) and anything written on this subject but I couldn't find answers to the questions "what happens when the aggregate function is set to None, where is the data stored, and how the heck I can get to it" (hint, hint :-).

Anyway, if you were to follow my advice about creating measure group with Account and Time, and set custom formula to aggregate Time as Average - you wouldn't have had this issue.

It is a good advice and I can see the simplifications it brings. However, setting the aggregate function to Average won't help anyway since I need a weighted average calculation over time. Hence, I still need to overwrite the total over time.

Friday, March 9, 2012

NON EMPTY

Hello
I have an MDX statement that looks like this:
SELECT
{ Measures.members } on Columns ,
{ CrossJoin( [Time].[Calendar].[2004].[May]:[Time].
[Calendar].[2004].[July],[Business].[User].[Business
Entity Id].[212].Children ) } on Rows
FROM UsageStats
And it returns this via a matrix report:
2004
|--|--|--|--|
| May | June | July |Total |
--|--|--|--|--|
Alan Smith | 2 | 3 | 2 | 7 |
Amy Marcus | | 3 | 3 | 6 |
Bob Fields | | | | |
Carry Grant | 1 | | | 1 |
--|--|--|--|--|
TOTAL | 3 | 6 | 5 | 14 |
--|--|--|--|--|
The report above represents hits to a website on a per-
Monthly basis for each user.
I would like to supress the empty rows so that Bob Fields,
above, won't show up at all. I tried using
NonEmptyCrossJoin like this:
SELECT
{ Measures.members } on Columns ,
{ NonEmptyCrossJoin( [Time].[Calendar].[2004].[May]:
[Time].[Calendar].[2004].[July],[Business].[User].
[Business Entity Id].[212].Children ) } on Rows
FROM UsageStats
and just NON EMPTY like this:
SELECT
{ Measures.members } on Columns ,
{ NonEmptyCrossJoin( [Time].[Calendar].[2004].[May]:
[Time].[Calendar].[2004].[July],[Business].[User].
[Business Entity Id].[212].Children ) } on Rows
FROM UsageStats
Both methods above supress the empty rows, but they also
supress anyone who hasn't had any hits to the site in the
first month, even if they do have hits in the 2nd or 3rd
months (so both Bob Fields, and Amy Marcus are both left
out of the report above).
Does anyone know how to possibly get around this? Any help
at all will be greatly appreciated!!! :D
Best regards
JanoYou might be able to use FILTER in conjunction with the CoalesceEmpty to
meet your need:
Example of CoalesceEmpty against Foodmart 2000 Sales cube to set
Measures.[Store Sales] to 0 for any Quarter that is empty:
=====================================================================WITH
MEMBER [Measures].[NonEmpty Sales] AS
'CoalesceEmpty(Measures.[Store Sales], 0)'
SELECT
CROSSJOIN( {[Time].[1997].children}, { [Measures].[NonEmpty
Sales] } )
ON COLUMNS,
CROSSJOIN( { [Store].[Store City].members }, {[Product].[Product
Department].members} )
ON ROWS
FROM Sales
=====================================================================
Now we add FILTER statement to remove any stores that did not have sales in
all Quarters:
=====================================================================WITH
MEMBER [Measures].[NonEmpty Sales] AS
'CoalesceEmpty(Measures.[Store Sales], 0)'
SELECT
CROSSJOIN( {[Time].[1997].children}, { [Measures].[NonEmpty
Sales] } )
ON COLUMNS,
FILTER(
CROSSJOIN( { [Store].[Store City].members }, {[Product].[Product
Department].members} ),
([Store].CurrentMember,
[Product].CurrentMember, [Measures].[NonEmpty Sales]) > 0 )
ON ROWS
FROM Sales
=====================================================================--
-- John H. Miller [MSFT]
-- SQL Server BI Product Group
----
--
"This posting is provided 'AS IS' with no warranties, and confers no
rights."
----
--
jhmiller@.online.microsoft.com
"Jano" <JanoBermudes@.microsoft.com> wrote in message
news:31d401c47eca$c1c7b200$a301280a@.phx.gbl...
> Hello
> I have an MDX statement that looks like this:
> SELECT
> { Measures.members } on Columns ,
> { CrossJoin( [Time].[Calendar].[2004].[May]:[Time].
> [Calendar].[2004].[July],[Business].[User].[Business
> Entity Id].[212].Children ) } on Rows
> FROM UsageStats
>
> And it returns this via a matrix report:
> 2004
> |--|--|--|--|
> | May | June | July |Total |
> --|--|--|--|--|
> Alan Smith | 2 | 3 | 2 | 7 |
> Amy Marcus | | 3 | 3 | 6 |
> Bob Fields | | | | |
> Carry Grant | 1 | | | 1 |
> --|--|--|--|--|
> TOTAL | 3 | 6 | 5 | 14 |
> --|--|--|--|--|
> The report above represents hits to a website on a per-
> Monthly basis for each user.
>
> I would like to supress the empty rows so that Bob Fields,
> above, won't show up at all. I tried using
> NonEmptyCrossJoin like this:
> SELECT
> { Measures.members } on Columns ,
> { NonEmptyCrossJoin( [Time].[Calendar].[2004].[May]:
> [Time].[Calendar].[2004].[July],[Business].[User].
> [Business Entity Id].[212].Children ) } on Rows
> FROM UsageStats
> and just NON EMPTY like this:
> SELECT
> { Measures.members } on Columns ,
> { NonEmptyCrossJoin( [Time].[Calendar].[2004].[May]:
> [Time].[Calendar].[2004].[July],[Business].[User].
> [Business Entity Id].[212].Children ) } on Rows
> FROM UsageStats
> Both methods above supress the empty rows, but they also
> supress anyone who hasn't had any hits to the site in the
> first month, even if they do have hits in the 2nd or 3rd
> months (so both Bob Fields, and Amy Marcus are both left
> out of the report above).
> Does anyone know how to possibly get around this? Any help
> at all will be greatly appreciated!!! :D
> Best regards
> Jano
>