简体   繁体   中英

How to get MDX openingperiod() to work as calculated measure in ssas cube

I want to use the MDX functions openingperiod() and closingperiod() in our cube, but cannot get it to work properly.

Is this actually possible, or are these functions only applicable in a MDX-query?

The main two articles I used to learn about openingperiod() are: https://www.sqlservercentral.com/steps/stairway-to-mdx-level-12-mdx-timedate-series-functions-openingperiod-and-closingperiod-functions

https://docs.microsoft.com/en-us/sql/mdx/openingperiod-mdx?view=sql-server-2017

In the above documentation the two functions openingperiod() and closingperiod() are only used in a query, but I want to integrate them in the cube.

The code I used as a regular query is:

sum(
openingperiod
    (
    [Date Booking].[Year Month],
    [Date Booking].[Year Month].currentmember
    ),
    [Measures].[Goods Amount])

The result should be the amount of goods at the start of the month, but the result is NULL .

I used sum to get a valid syntax that points to the right member.

I will try to give you the idea from Adventure Works sample database.

This should be the syntax to create your calculated member in the cube ([Adventure Works] is the cube name in this example), so you can call it later:

create member [Adventure Works].Measures.MyMeasure4
as
(OpeningPeriod([Date].[Calendar].[Date],[Date].[Calendar].Currentmember.Parent), [Measures].[Internet Sales Amount]) 

And then you should call it like this to see the result:

select {Measures.MyMeasure4, [Measures].[Internet Sales Amount]} on 0,
[Date].[Calendar].members on 1
from [Adventure Works]

So for January, MyMeasure4 will have the value of January the 1st member (value for opening period), for February it will have the value from Feb the 1st, if that was your intention.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM