How can I merge two members into one in a query?

后端 未结 1 1217
轻奢々
轻奢々 2021-01-05 17:52

On rows, I basically want to select all the members of a hierarchy but would like to combine two of them into one. For example, the members would include A,

1条回答
  •  离开以前
    2021-01-05 18:02

    The error you're seeing is because of your syntax with the parentheses: (a, b, c) defines a tuple where a, b, and c are each members from a different dimension. If you're trying to union these members together, you should use the shorthand: {a, b, c}.

    Now, to combine the members is possible, although maybe not as clean and easy as you would want. Here's an example of one way to do it, by creating a new member and then excluding (via Except) the original members from the hierarchy.

    WITH 
        SET [Combined] AS {
            [Customer].[Customer Geography].[Country].&[France], 
            [Customer].[Customer Geography].[Country].&[Germany]
        }
        MEMBER [Customer].[Customer Geography].[France & Germany] AS Aggregate([Combined])
    SELECT
        [Measures].[Internet Sales Amount] ON 0,
        Union(
            Except([Customer].[Customer Geography].[Country], [Combined]),
            [Customer].[Customer Geography].[France & Germany]
        ) ON 1
    FROM [Adventure Works]
    

    Results:

                      Internet Sales Amount
    Australia                 $9,061,000.58
    Canada                    $1,977,844.86
    United Kingdom            $3,391,712.21
    United States             $9,389,789.51
    France & Germany          $5,538,330.05
    

    Hope that helps set you on the right track.

    0 讨论(0)
提交回复
热议问题