An SSAS head-scratcher.....

  • Hi Folks,

    I'm getting some weird behavior in SSAS and I'm posting to see if it has happened to anyone else or if anyone knows how to resolve it.

    So I have two time differences that need to be averaged out and I go about it like so:

    1) In the source data there is a DATEDIFF(Second, StartDateTime, EndDateTime) calculation. This is working as expected and is used to create a hidden measure in my cube.

    2) I then get an average from the above by doing [Measures].[Seconds]/[Measures].[Some Number].

    3) As the client wants to see an HH:MM string of this average time I have the following calculated member:

    IIF([Measures].[Respond Sec] = NULL, NULL,

    -- Hours

    IIF ([Measures].[Respond Sec] < 60*60,

    '00',

    IIF([Measures].[Respond Sec] < 36000,

    '0' + CStr(Int([Measures].[Respond Sec]/60/60)),

    CStr(Int([Measures].[Respond Sec]/60/60)))

    ) + ':'

    -- Minutes

    +

    IIF ([Measures].[Respond Sec] < 60, '00',

    IIF ([Measures].[Respond Sec] < 600,

    CStr(Int(

    ([Measures].[Respond Sec] - Int([Measures].[Respond Sec]/60/60)*60*60)

    /60))

    ,

    RIGHT('0' + CStr(Int(

    ([Measures].[Respond Sec] - Int([Measures].[Respond Sec]/60/60)*60*60)

    /60))

    , 2)

    )

    )

    )

    Like I mentioned before I am doing this for 2 things (response and fix times). The response times work perfectly. The fix times are what is weird. It appears that they work......sometimes. For some reason for two of the years of data the year total is a massive negative number (this is the original calc and not the HH:MM bit as above, that just returns 00:00). If you drill into the date hierarchy though there are no negatives and it appears to be working fine?????

    I've looked through the source data and there are no negative values. I've played around with the DATEDIFF at source by CASEing it as NULL if there is no fix datetime (I think this is the default behavior of DATEDIFF anyway but I wanted to be sure) but no. I even tried casting it as a BIGINT just in case that was the issue, still no.

    There is no difference between the way I get the data for response times except it uses a different datetime column, so why is one working and the other not?

    Does anyone have any ideas please???

    Thanks in advance 🙂


    I'm on LinkedIn

  • What is the need to create a formatted measure in the cube. If you have data available as seconds you can easily cast the value as HH:MM:SS in the SSRS report.

    Raunak J

  • Thanks for your comment, although that's not really the issue. The reason I am doing it in MDX is that the client needs to analyze the data dynamically and won't be using SSRS for static reporting, otherwise yes I would do it in SSRS. I included the MDX above for completeness.

    The actual issue is that there is an integer value which is correct at source but when processed in SSAS at certain hierarchical levels (always 2 out of however many for some reason) is showing as a large negative value before any of the MDX above is applied.

    If you could share your thoughts on that I would be grateful 🙂


    I'm on LinkedIn

  • I have received an answer on the MSDN forums (word, Greg Galloway! ). It would seem that this problem is caused by overloading an INT data type. I changed it all to BIGINT (in the source and the measure itself) and it fixed it. You learn something new every day 🙂


    I'm on LinkedIn

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply