invalid cast exception on warehouse build


I created a calculated field in the data cube that’s a timespan, and no errors show up while editing the cube, but on building the cube, this error comes up:

Error: System.InvalidCastException: Unable to cast object of type ‘System.TimeSpan’ to type ‘System.IConvertible’.

What does it mean and how can I resolve it?

I don’t know the exact details of your situation but have experienced similar.

It seems that when editing and previewing the cube, only the first rows are processed and if they are ok, then no exceptions are raised. Once you build it then all the rows are processed and any errors further down the data will be discovered.

It looks like the calculated field that you created is trying to turn a timespan into something else (I have never seen the convertible type before) and that can’t be done.

I’m not sure exactly how to resolve it, and don’t know how to figure out exactly which row and values are causing the problem. What I do is defensively program the calculated field with many if statements to make sure I only convert data that I can cope with otherwise return null or something else.

1 Like

Another team member had a similar issue today (I’d just given up and worked with separate hours, minutes, etc. as the timespan was a ‘nice to have’ for the moment), and we worked out that although Dundas shows this as valid and previews it, it will only build the cube if you return a new DateTime from the timespan (assigning it a date).

For his problem, this didn’t resolve the issue as he needed average times, so he ended up calculating the average seconds, then creating separate hours, minutes, and seconds from that field and adding them together in the Custom Text of the field with colons between them, then setting the custom text formatting of each to 00 to show the leading zeroes.