multidimensional expressions (MDX) calculation error in SSAS Cube

Hongyi Jin 0 Reputation points
2023-03-29T18:06:19.05+00:00

I just got a project handover regarding SSAS cubes and multidimensional expressions. There is a calculation written in Visual Studio:

(StrToMember(
"[DIM Time_V3].[Year -  Week -  Date].[Month].&["+
MID(MemberToStr([DIM Time_V3].[Year - Month - Day].CurrentMember)
,44,11)+"T00:00:00]"),[Plan Revenue])

This formula is not working with unknown reasons (The excel pivot table showing #VALUE! under this formula).

I converted the above formula into MDX Query in SSMS:

SELECT 
[Measures].[Plan Revenue] ON COLUMNS,
StrToMember(
              "[DIM Time_V3].[Year -  Week -  Date].[Month].&[" 
              + MID(MemberToStr([DIM Time_V3].[Year - Month - Day].CurrentMember),44,11) 
              + "T00:00:00]"
            ) ON ROWS
FROM [FR_ACCOUNTING 3]

There is an error says "The 'T00:00:00' string cannot be converted to the date type". I then tried following two query scripts:

SELECT  [Measures].[Plan Revenue] ON COLUMNS,
        [DIM Time_V3].[Year -  Week -  Date].[Month] ON ROWS
FROM [FR_ACCOUNTING 3]

Here is a random member of above query result:

Caption Manufacturing Period 1, 2023
Name    [DIM TIME_V3].[Year -  Week -  Date].[Month].&[2023-01-03T00:00:00]
UniqueName  [DIM TIME_V3].[Year -  Week -  Date].[Month].&[2023-01-03T00:00:00]
Description 
LevelName   [DIM TIME_V3].[Year -  Week -  Date].[Month]
LevelDepth  3
DrilledDown False
ParentSameAsPrevious    False
ChildCount  4
SELECT  [Measures].[Plan Revenue] ON COLUMNS,
        [DIM Time_V3].[Year - Month - Day].[Manufacturing Month] ON ROWS
FROM [FR_ACCOUNTING 3]

And here is a random member of above query result:

Caption Manufacturing Period 1, 2023
Name    [DIM TIME_V3].[Year - Month - Day].[Manufacturing Month].&[2023-01-03T00:00:00]
UniqueName  [DIM TIME_V3].[Year - Month - Day].[Manufacturing Month].&[2023-01-03T00:00:00]
Description 
LevelName   [DIM TIME_V3].[Year - Month - Day].[Manufacturing Month]
LevelDepth  2
DrilledDown False
ParentSameAsPrevious    False
ChildCount  28

I also tried following code to see if hardcoding instead of MID function can return something:

SELECT 
[Measures].[Plan Revenue] ON COLUMNS,
StrToMember(
              "[DIM Time_V3].[Year -  Week -  Date].[Month].&["
              + "2023-01-03"
              + "T00:00:00]"
            ) ON ROWS
FROM [FR_ACCOUNTING 3]

The query successfully returned a value.

Finally I tried following code:

--Check if MID function works for manufacturing calendar
SELECT 
[Measures].[Plan Revenue] ON COLUMNS,
StrToMember(
              "[DIM Time_V3].[Year -  Week -  Date].[Month].&[" 
              + MID(MemberToStr([DIM Time_V3].[Year - Month - Day].CurrentMember),44,11) 
              + "]"
            ) ON ROWS
FROM [FR_ACCOUNTING 3]

The result says "The '' string cannot be converted to the date type".

In conclusion, the reason why error occurs is that the MID function did not extract the correct date format (yyyy-mm-dd) from a member, but I do not know how to solve this issue.

I am so curious how does MID function work and how do we extract a substring of a member. So much appreciated for solving my problem.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,638 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,801 questions
SQL Server Analysis Services
SQL Server Analysis Services
A Microsoft online analytical data engine used in decision support and business analytics, providing the analytical data for business reports and client applications such as Power BI, Excel, Reporting Services reports, and other data visualization tools.
1,246 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Alexei Stoyanovsky 3,416 Reputation points
    2023-03-30T06:18:37.1966667+00:00

    This is one horrific way of finding the month member in the YWD hierarchy corresponding to the current position along the YMD hierarchy. Such operations should utilize attribute relationships and EXISTS.

    0 comments No comments