简体   繁体   中英

List Dimension Members if selected date falls between Start Date and End Date in fact records SSAS MDX

I have a fact table that contains invoice line items, and since these line items are subscriptions, there is a Start Date and an End Date involved

LineItem Customer       Product         OrderDate       StartDate       EndDate
1        Customer A     Product A       1/1/2013        1/1/2013        3/1/2013
2        Customer A     Product B       1/1/2013        1/1/2013        4/1/2013
3        Customer B     Product A       1/1/2013        2/1/2013        6/1/2013

The client wants a list of Active Customers for a selected date in Excel(PivotTable). They want to select a date, and if the date falls between the Start Date and End Date of any Invoice Line Item record, then the Customer should be displayed. For example:

If '1/5/2013' is selected, the Customer List should return (LineItem: 1, 2): Customer A

If '2/10/2013' is selected, the Customer List should return (LineItem: 1,2,3): Customer A Customer B

If '5/15/2013' is selected, the Customer List should return (LineItem: 3): Customer B

Next, the client wants to filter by Products as well, so:

If '3/20/2013' is selected and Product A is selected, the Customer List should return (LineItem: 3): Customer B

In SQL this is very easy:

Select Distinct Customer from Fact where @SelectedDate between StartDate and EndDate

I am unsure on how to approach this problem in SSAS and what to do with the 'Selected Date' as in, should this be another dimension? if so how is it going to relate to the Fact Table?

Or can this be done on Excel/PowerPivot side using in some other way?

Also my initial approach is to create a Named Set of customers - but I am not sure how to create it based on date range etc.

Any help will be appreciated! Thanks

If you are able to write the MDX, then you can do this as follows, assuming there is a date dimension table with two foreign keys to it from the fact table, the role playing dimensions are named [Start Date] and [End Date] , and @SelectedDate is a string matching the format of your date keys:

SELECT {}
       ON COLUMNS,
       [Customer].[Customer Name].Members
       ON ROWS
  FROM [Cube]
 WHERE (null : StrToMember('[Start Date].[Date].[' + @SelectedDate + ']'))
       *
       (StrToMember('[End Date].[Date].[' + @SelectedDate + ']'): null)

The WHERE clause is a cross product of two sets: one set of start dates that contains all from the first one appearing in the dimension to the selected date, and one of end dates that contains all end dates from the selected date to the last one in the cube.

However, I do not think it is possible for users to get Excel to run this type of statement somehow, except via a VBA or Excel plugin solution. I think that should be possible, but have no experience with that.

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