Calculating the number of days in a time dimension node - with Grand Total

℡╲_俬逩灬. 提交于 2019-12-08 04:58:38

问题


I need to know the number of days in a time dimension period for calculating weighted averages. I am using the following expression in a calculated measure to obtain the number of days in the current dimension member:

Count(
    Descendants(
        [Date].[Calendar].CurrentMember,
        [Date].[Calendar].[Date Key]
    )   
)

This works fine for all drill-down situations, but it does not work for the Grand Total when I have a filter. I suspect that CurrentMember does not work in this situation. It always returns the total number of days in my data. To illustrate, the measure with the above formula is aggregated in BIDS as follows

because my fact data starts in 1984 and there are 11100 days in the time dimension. How can I change the formula so that the filter is accounted for in the aggregation? Users can drill down to the Day level. Here is the Excel Pivot table:


回答1:


If you need to filter members from [Date].[Calendar].[Date Key] level you can intersect descendants result with the actual filter>

WITH 
  MEMBER [Measures].[a] AS 
    Count
    (
      Intersect
      (
        Descendants
        (
          [Date].[Calendar].CurrentMember
         ,[Date].[Calendar].[Date]
        )
       ,Filter
        (
          [Date].[Calendar].[Date].MEMBERS
         ,
          ([Measures].[Sales Amount],[Date].[Calendar].CurrentMember) > 10000
        )
      )
    ) 
SELECT 
  {[Date].[Calendar].[Calendar Year].MEMBERS} ON ROWS
 ,{[Measures].[a]} ON COLUMNS
FROM [Adventure Works]



回答2:


I believe that this is a classic case of the "Multiselect Issue with Calculated Members". I found a good summary here. I have a solution that works in Excel. It does not calculate the proper totals in BIDS, but that's not an issue in this case.

I use the following dynamic set (this is the Script view on the Calculations tab in the cube editor):

CALCULATE;     

CREATE MEMBER CURRENTCUBE.[Measures].[Days In Period Count]
AS Count(Existing [Filtered Date]), VISIBLE = 1  ; 

CREATE DYNAMIC SET CURRENTCUBE.[Filtered Date]
AS [Date].[Calendar].[Date Key] ; 

My interpretation is that SSAS normally calculates the aggregate in advance and that [Date].[Calendar].CurrentMember is not meaningful at the Grand Total level outside of the context of a user's drill-down and filter action. By using a dynamic set, I am forcing SSAS to calculate the aggregate dynamically. There is a theoretical performance hit, but with my cube size I did not notice much of a difference.

Then BIDS shows the following totals - no change from above yet:

But Excel has the correct totals that reflect only the filtered date coordinates (in this case, only Q1 of 2012 and the entire year of 2013):



来源:https://stackoverflow.com/questions/17820202/calculating-the-number-of-days-in-a-time-dimension-node-with-grand-total

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!