2
votes

In my SSAS cube I have a dimension that includes 6 date fields. They are all defined in the same way, with a Key field that is a date type and a Name field that is char(10) in format yyyy-mm-dd.

When I include those fields in an Excel pivot table, they all work fine except one. That one field is displayed correctly, but doesn't behave correctly when filtered. In particular, specifying a between filter always returns zero rows. Same with a greater than filter. Begins with works fine.

Once again, this only happens for one of the six date fields. But all six date fields are configured identically as far as I can tell. What type of mistake could cause this?

EDIT

Using SQLServer Profiler I can see that the MDX generated from Excel are identical for the dates that work and the one that doesn't (except for the field names changing of course). If I restrict the pivot table to a single date and add a between filter then the MDX is:

SELECT NON EMPTY Hierarchize({DrilldownLevel({[Participation Program].[Participation Start Date].[All]},,,INCLUDE_CALC_MEMBERS)}) 
    DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON COLUMNS  
FROM (SELECT Filter([Participation Program].[Participation Start Date].[Participation Start Date].AllMembers, 
                   ([Participation Program].[Participation Start Date].CurrentMember.member_caption>="1985" 
                    AND [Participation Program].[Participation Start Date].CurrentMember.member_caption<="1990")) ON COLUMNS  
        FROM [Compass3]) 
WHERE ([Child].[Child is Handicapped].&[T],[Measures].[Child Count]) CELL PROPERTIES VALUE, FORMAT_STRING, LANGUAGE, BACK_COLOR, FORE_COLOR, FONT_FLAGS

That returns correct results for [Participation Start Date], but if I do the same thing with [Participation Stop Date] it returns 0 results. So it is a problem on the SSAS side rather than Excel side. But I still can see no difference in the way the two dates are configured in the cube, and I am 100% certain that there is data that should match the specified date range.

2
Do you just use years in your filter? Does it behave differently when you enter months/days like "1985-03" or "2010-05-01"? Maybe AS is converting "1985" to an int before comparing.FrankPl
I have tried defining the Excel filter in various formats, including the ones you suggested. I have also tried things like "Between 0 and 999999". All have the same effect: zero rows returned.MattClarke

2 Answers

1
votes

I would change the Key for those attributes to a numeric representation of the date in YYYYMMDD format. I would achieve this via a SQL View where I would use the CONVERT function.

I would not use the date datatype at all in SSAS, as it's internal representation is obscure/uncertain.

1
votes

I've come across a similar problem using epplus. If you haven't defined the date explicitly, Excel may not realize that the data is a date. This causes problems with sorts and filtering. (Note that the code below is C#, but the idea behind it with respect to the excel formulas/formats should be the same.)

When you generate the excel cell, explicitly define a date formula in the cell:

ws.Cells[rowCount, columnCount].Formula = "=DATE(" + myDate.ToString("yyyy,M,d") + ")";

Then, set the cell formatting to display the date the way you want:

ws.Cells[rowCounter, columnCount].Style.Numberformat.Format = "d-mmm-yyyy";