Showing posts with label olap. Show all posts
Showing posts with label olap. Show all posts

Friday, March 23, 2012

Median calculation

I want to calculate the MEDIAN time interval between the two date field. In an OLAP cube one of the dimension consists of the two date fields as well as Interval(days) field (calculated at the data source view). How to create a Measure in the OLAP cube to calculate the MEDIAN Interval?

MEDIAN( <<Set>>[, <<Numeric Expression>>])

Since I'm not sure of the details your dimension, here's an Adventure Works sample query, for the Median duration in days of a Promotion:

>>

With Member [Measures].[MedPromoDays] as

Median(existing [Promotion].[Promotion].[Promotion],

DateDiff("d", [Promotion].[Promotion].Properties("Start Date", TYPED),

[Promotion].[Promotion].Properties("End Date", TYPED)))

select {[Measures].[MedPromoDays]} on 0,

[Promotion].[Promotion Type].Members on 1

from [Adventure Works]

MedPromoDays
All Promotions 83.5
Discontinued Product 53
Excess Inventory 61
New Product 91
No Discount 1309
Seasonal Discount 30
Volume Discount 1095

>>

|||

And to slightly change Deepak's query to be more efficient:

With Member [Measures].[MedPromoDays] as

Median(existing [Promotion].[Promotion].[Promotion],

DateDiff("d", [Promotion].[Start Date].MemberValue,

[Promotion].[End Date].MemberValue))

select {[Measures].[MedPromoDays]} on 0,

[Promotion].[Promotion Type].Members on 1

from [Adventure Works]

Monday, March 19, 2012

MEASURE PROPERTIES

I have a report that has multiple measures coming from an OLAP data source.
Some of these measures are counts, some are % and some are $. How can I set
the format property for each. Thanks.
--
Michael Hardy
ETL Developer
Visit our web pages:
www.atlantis.com
www.oceanclub.com
www.oneandonlyresorts.com
www.kerzner.comIn RS 2000, you have to set format codes on the textboxes where you show the
field values.
E.g. P0 for percentages without decimals, P2 for percentages with two
decimals, C for currency values, etc. More information on format codes is
available on MSDN:
*
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconstandardnumericformatstrings.asp
*
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcustomnumericformatstrings.asp
NOTE: format codes only have an effect if the contents of the textbox is not
a string, but a numeric data type. You might need to use conversion
functions to make sure the value is a numeric value. Common conversion
functions are listed here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vagrptypeconversion.asp
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Opuspocus" <Michael.Hardy@.Kerzner.Com> wrote in message
news:427B1A97-96CB-48F7-B7F0-3A88F79B50E5@.microsoft.com...
> I have a report that has multiple measures coming from an OLAP data
source.
> Some of these measures are counts, some are % and some are $. How can I
set
> the format property for each. Thanks.
> --
> Michael Hardy
> ETL Developer
> Visit our web pages:
> www.atlantis.com
> www.oceanclub.com
> www.oneandonlyresorts.com
> www.kerzner.com
>

Monday, March 12, 2012

MDX, Matrix and Aggregate()

All,

I keep reading that the Matrix is the perfect tool to use with OLAP data, but I am very confused about the efficacy of such a notion. As we know, OLAP is about precalculated aggregations, and the noticeable performance improvements that such an analytical database yields.

But RS answer to all of this is to calculate the aggregations at run-time,they recommend to bring in the leaf level data from the cubes, and then let RS aggregate the results at runtime.

This may an acceptable approach for simple MDX queries, but for advanced analysis -- it just does not make good sense.

We desperately want to use RS for our Enterprise Reporting solution, but we are hard pressed to justify the performance issues (Cellset flattening + run-time aggregations) and the complexity of a MDX/ Matrix solution (if one exists)

Any examples of a multiple group (rows and columns) Matrix using an MDX

datasource would be appreciated!!!

Thanks,

Jim

Are you asking about RS 2000 or RS 2005?

MDX queries designed in graphical query designer of RS 2005 can retrieve AS server aggregates directly within the query. You would then use the =Aggregate(...) function within the matrix cells instead of using regular aggregations. Based on the matrix cells' scopes, the Aggregate(...) function will determine the correct aggregate row from the flattened rowset. However, this means that the aggregate rows must be present and retrieved by the MDX query in the first place. Adjusting the MDX query based on the usage of the Aggregate function within the report is taken care of automatically by report designer if you designed the MDX query with the graphical MDX query designer of RS 2005.

-- Robert

|||

Robert,

Thanks for getting back to me -- I'm using RS 2000, so the good news is that it sounds like RS 2005 has addressed the issue of the MDX / Matrix complexity.

Any ideas on RS 2000? We won't be going to 2005 until Q1 2007.

Thanks,

Jim

|||

Technically, you could implement a full custom data extension for RS 2000. That data extension would need to implement the IDataReaderExtension interface (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/RSPROG/htm/rsp_ref_clr_dataproc_8je0.asp) among other interfaces and identify aggregate rows within the flattened rowset returned from a AS 2000 server.

However, this is a non-trivial task and requires a lot of effort to get everything working. Btw, RS 2000 already supports the Aggregate function - so you would then use it as described in my previous posting. Anyway, the Aggregate function is only useful if with a data extension that implements the IDataReaderExtension interface. None of the RS 2000 data extensions implement that functionality however.

Specific support for AS server aggregates is a feature that was added in RS 2005 in combination with a new RS 2005 Analysis Services data extension that works on top of the new AS 2005 AdoMd data provider.

-- Robert

|||

When I use the Aggregate() function instead of the default Sum() function in subtotals RS2005 returns nothing, i.e. it doesn't work.

The problem in all its simplicity: I have two measures in my MDX query:

Sales in dollars (can use Sum for subtotals)

Saturday, February 25, 2012

MDX queries on SQL Server OLAP using Java

Hi,

We are trying use MS SQL Server OLAP and we want to fire MDX queries to SQL Server OLAP using Java. Can someone guide me on how can we do this?

Regards,

~Kanchan.

As an example you can take a look at this open source project: REX http://sourceforge.net/projects/whex/

It is written in Java, and it is general purpose OLAP client tool which works against Analysis Services. Since it's open source you can go through the code and see how it works.

HTH,

Mosha (http://www.mosha.com/msolap)

Monday, February 20, 2012

MDX in MS Reporting Services

Hi

(All using 2005 release)

I've written a MSRS report based on an OLAP data source which is working fine in the report designer but once I have deployed it to the report server & attempt to browse it I get the following errror:

An error has occurred during report processing.

Query execution failed for data set 'DataSet1'.
Line 1: Incorrect syntax near '{'. Line 1: Incorrect syntax near 'Tbl Acc Codes'

It seems to be pointing to an mdx error although I've constructed the query just by using the drag & drop tool.

Are there any known problems with MSRS & MDX & if not can any of you MDX gurus spot anything wrong with the qry:

SELECT NON EMPTY { [Measures].[Ratio Val] } ON COLUMNS, NON EMPTY { ([Tbl Ac Year].[AcYear].[AcYear].ALLMEMBERS * [Tbl Comparison Group].[Tbl Comparison Group].[Tbl Comparison Group].ALLMEMBERS * [Tbl Comparison Group].[Description].[Description].ALLMEMBERS * [Tbl Group].[Tbl Group].[Tbl Group].ALLMEMBERS * [Tbl Group].[Display Order].[Display Order].ALLMEMBERS * [Tbl Clients].[Tbl Clients].[Tbl Clients].ALLMEMBERS * [Tbl Acc Codes].[Acc Desc Hierarchy].[Description].ALLMEMBERS * [Tbl Acc Codes].[Acc Code Hierarchy].[Tbl Acc Codes].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM [FE Benchmark] CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS

Thanks :)

Wayne

  • Try and paste your query into MDX editor in SQL Managment Studio. It will allow you to perform a syntax check on your query.

    Edward.
    --
    This posting is provided "AS IS" with no warranties, and confers no rights.

  • MDX help

    Hi All,

    I have a calculated measure in my OLAP cube which is a distinct count of one of the keys in the Fact table. This is a semi-additive measure so I need Distinct count of the last child of this measure. How can I do this? Is there a built-in function to handle this.

    I am using AS 2005.

    Any help would be greatly appreciated.

    Rohit

    Hi Rohit. More detail here is helpful. You ask for LastChild of a measure. Unfortunately, measures don't have a hierarchy so they don't have children. This means you're probably asking for one of the following:

    (1) The LastChild within a hierarchy (such as Product), and the corresponding value of your semi-additive measure (what's the name of the measure?)

    OR

    (2) The 'closing' value of your semi-additive measure across time.

    Are you asking for one of the above options, or something else. An example would be very useful.

    PGoldy

    |||

    Paul,

    The calculated measure is MarketCount (distinct count of MarketKey). I am looking for the closing value of the measure across time.

    The MarketCount is a monthly snapshot and should not be added across time.

    For example, if the MarketCount is 110 in July and 120 in Aug, when the user browses the data in the cube for the months of July and August, the MarketCount should display as 120 and not as 230.

    Thanks.

    Rohit

    |||

    SSAS 2005 does have built-in support for semi-additive measures like last child, but only in the Enterprise Edition

    http://msdn2.microsoft.com/en-us/library/ms189734.aspx

    If you have the standard edition you could achieve the same results through calculations in the MDX script (although the performance would not be as good as the built-in feature)

    |||

    I am aware of the built in function for Last Child but I need to find the Distinct Count of the Last Child of one of the Fact keys. Please refer to my previous post for further details.

    Paul, any ideas?

    Rohit

    |||

    Hi Rohit:

    I'm operating on a couple of assumptions here: (1) Calendar hirrearchy has structure: AllCalendar->Year->Quarter->Month (2) The lowest level in Calendar where MarketCount is valid is Month. (3) You want to see the MarketCount for the last month in the higher selected time period (Quarter, or Year). As an example, the MarketCount value for March 2006 is 130, then the Ending_MarketCount for Q1 2006 is also 130. Here's a calculated member definition for Ending_MarketCount based on my assumptions:

    (TAIL(DESCENDANTS(Calendars.Calendars.CurrentMember, [Calendars].[Calendars].[Month]), 1).Item(0), Measures.MarketCount))

    The use of TAIL(DESCENDANTS() finds the last month in the quarter if quarter is the current time level. It also finds the last month in the year if Year is the current time level, and defaults to the current month if a month is the current calendar selection.

    Hope this helps.

    PGoldy

    |||

    Sorry, I left an extra parentheses on the end of the calculated member definition. Here is the corrected definition:

    (TAIL(DESCENDANTS(Calendars.Calendars.CurrentMember, [Calendars].[Calendars].[Month]), 1).Item(0), Measures.MarketCount)

    PGoldy

    |||

    Have you thought about what you want the users to see when the data is incomplete?

    For example, if we currently only have data up to August, but the users want to see the value as at calendar quarter Q3, should they see 0, because September currently has no value? Or should the calculation display the last non empty child (August)?

    Wrapping the descendants function with NonEmpty() would give you "Last Non Empty Child" behaviour, but whether you need this or not depends what your business requirements are.

    eg.

    (TAIL(NONEMPTY(DESCENDANTS(Calendars.Calendars.CurrentMember, [Calendars].[Calendars].[Month])), 1).Item(0), Measures.MarketCount)

    ...just a thought

    |||

    Hi Paul,

    I tried your suggestion but it did not work. I might be missing something. Let me explain my scenario in more detail.

    I have the following dimensions -

    DimTime - Hierarchy is Year - Quarter - Month (This dimension table has a granularity of date but I have set the granularity for this dimension in the cube to month level. Would this be a problem? I need the date for other Facts which are not part of the cube in question.)

    DimMarket

    DimInstrumentModel

    DimTerritory (Geography)

    I have an aggregate Fact Table 'FactInstallBase' which has a monthly snapshot of the instruments installed and active at various customer sites. Each customer can have one or more instruments. A few sample records in the Fact table look as follows

    MarketKey InstrumentModelKey TimeKey TerritoryKey InstrumentCount

    123 111 222 333 2

    123 112 222 333 1

    125 111 222 444 2

    There is a requirement to display a count of the markets that own instruments belonging to a certain Instrument model. The users browse the cube using Excel pivot table.

    I have created a calculated measure 'MarketCount' and set the aggregation for this measure to DIstinctCount of MarketKey. This works fine when the users browse only one month's data. But when the user's select multiple months like Jan-2006 and Feb-2006, this mesaure gets added for both the months. If the Distinct Market Count for Jan '06 is 110 and for Feb '06 is 120 the MarketCount is displayed as 230 (110+120). This measure is semi-additive and should not be added over time. So even if the user selects multiple months, the MarketCount measure should display as the last month's MarketCount (In this case 120). Am I doing something wrong?

    Any help would be greatly appreciated.

    Rohit

    |||

    Paul,

    I changed the granularity in my Time Dimension table to Month. The hierarchy for this dimension is Year - Quarter - Month but the MDX code you sent for the calculated measure still does not work.

    Rohit

    MDX help

    Hi All,

    I have a calculated measure in my OLAP cube which is a distinct count of one of the keys in the Fact table. This is a semi-additive measure so I need Distinct count of the last child of this measure. How can I do this? Is there a built-in function to handle this.

    I am using AS 2005.

    Any help would be greatly appreciated.

    Rohit

    Hi Rohit. More detail here is helpful. You ask for LastChild of a measure. Unfortunately, measures don't have a hierarchy so they don't have children. This means you're probably asking for one of the following:

    (1) The LastChild within a hierarchy (such as Product), and the corresponding value of your semi-additive measure (what's the name of the measure?)

    OR

    (2) The 'closing' value of your semi-additive measure across time.

    Are you asking for one of the above options, or something else. An example would be very useful.

    PGoldy

    |||

    Paul,

    The calculated measure is MarketCount (distinct count of MarketKey). I am looking for the closing value of the measure across time.

    The MarketCount is a monthly snapshot and should not be added across time.

    For example, if the MarketCount is 110 in July and 120 in Aug, when the user browses the data in the cube for the months of July and August, the MarketCount should display as 120 and not as 230.

    Thanks.

    Rohit

    |||

    SSAS 2005 does have built-in support for semi-additive measures like last child, but only in the Enterprise Edition

    http://msdn2.microsoft.com/en-us/library/ms189734.aspx

    If you have the standard edition you could achieve the same results through calculations in the MDX script (although the performance would not be as good as the built-in feature)

    |||

    I am aware of the built in function for Last Child but I need to find the Distinct Count of the Last Child of one of the Fact keys. Please refer to my previous post for further details.

    Paul, any ideas?

    Rohit

    |||

    Hi Rohit:

    I'm operating on a couple of assumptions here: (1) Calendar hirrearchy has structure: AllCalendar->Year->Quarter->Month (2) The lowest level in Calendar where MarketCount is valid is Month. (3) You want to see the MarketCount for the last month in the higher selected time period (Quarter, or Year). As an example, the MarketCount value for March 2006 is 130, then the Ending_MarketCount for Q1 2006 is also 130. Here's a calculated member definition for Ending_MarketCount based on my assumptions:

    (TAIL(DESCENDANTS(Calendars.Calendars.CurrentMember, [Calendars].[Calendars].[Month]), 1).Item(0), Measures.MarketCount))

    The use of TAIL(DESCENDANTS() finds the last month in the quarter if quarter is the current time level. It also finds the last month in the year if Year is the current time level, and defaults to the current month if a month is the current calendar selection.

    Hope this helps.

    PGoldy

    |||

    Sorry, I left an extra parentheses on the end of the calculated member definition. Here is the corrected definition:

    (TAIL(DESCENDANTS(Calendars.Calendars.CurrentMember, [Calendars].[Calendars].[Month]), 1).Item(0), Measures.MarketCount)

    PGoldy

    |||

    Have you thought about what you want the users to see when the data is incomplete?

    For example, if we currently only have data up to August, but the users want to see the value as at calendar quarter Q3, should they see 0, because September currently has no value? Or should the calculation display the last non empty child (August)?

    Wrapping the descendants function with NonEmpty() would give you "Last Non Empty Child" behaviour, but whether you need this or not depends what your business requirements are.

    eg.

    (TAIL(NONEMPTY(DESCENDANTS(Calendars.Calendars.CurrentMember, [Calendars].[Calendars].[Month])), 1).Item(0), Measures.MarketCount)

    ...just a thought

    |||

    Hi Paul,

    I tried your suggestion but it did not work. I might be missing something. Let me explain my scenario in more detail.

    I have the following dimensions -

    DimTime - Hierarchy is Year - Quarter - Month (This dimension table has a granularity of date but I have set the granularity for this dimension in the cube to month level. Would this be a problem? I need the date for other Facts which are not part of the cube in question.)

    DimMarket

    DimInstrumentModel

    DimTerritory (Geography)

    I have an aggregate Fact Table 'FactInstallBase' which has a monthly snapshot of the instruments installed and active at various customer sites. Each customer can have one or more instruments. A few sample records in the Fact table look as follows

    MarketKey InstrumentModelKey TimeKey TerritoryKey InstrumentCount

    123 111 222 333 2

    123 112 222 333 1

    125 111 222 444 2

    There is a requirement to display a count of the markets that own instruments belonging to a certain Instrument model. The users browse the cube using Excel pivot table.

    I have created a calculated measure 'MarketCount' and set the aggregation for this measure to DIstinctCount of MarketKey. This works fine when the users browse only one month's data. But when the user's select multiple months like Jan-2006 and Feb-2006, this mesaure gets added for both the months. If the Distinct Market Count for Jan '06 is 110 and for Feb '06 is 120 the MarketCount is displayed as 230 (110+120). This measure is semi-additive and should not be added over time. So even if the user selects multiple months, the MarketCount measure should display as the last month's MarketCount (In this case 120). Am I doing something wrong?

    Any help would be greatly appreciated.

    Rohit

    |||

    Paul,

    I changed the granularity in my Time Dimension table to Month. The hierarchy for this dimension is Year - Quarter - Month but the MDX code you sent for the calculated measure still does not work.

    Rohit