1

It seems I am struggling to understand the difference between a set and a tuple in MDX. I've read very fancy definitions comparing the two, but the only difference to me seems that 'A set has the same-type members' and 'A tuple has non-same-type members'. Other than that, any definition I read or come across (talking about dimensional space or what-not) seems to make no sense. The 'one-item' I get:

# Tuple
[Team].[Hierarchy].[Code].[DET]

And then multiple items with that same type (dimensionality) is a set, ok:

{[Team].[Hierarchy].[Code].[DET], [Team].[Hierarchy].[Code].[DAL]}

But here are a few examples that don't make sense to me:

# How is this a set? It just has two exact same items!
{[Team].[Hierarchy].[Code].[DET], [Team].[Hierarchy].[Code].[DET]}

And another example:

# Tuple (again, same thing -- now adding a duplicate attribute
(
    {[Team].[Hierarchy].[Code].[DET],[Team].[Hierarchy].[Code].[DET]},
    [Team].[Name].[Name].[Detroit Lions]
)

Now since both of these are almost doing the same thing (and neither references a measure, so neither would be self-sufficient to pull a 'value'), what is the actual difference between a tuple and a set? These seem to be so loosely defined in the language (for example, above I can have duplicate members in a set, which is usually not allowed in a set).


A related question (some of the answers cover the basics of a one-level set/tuple difference but don't go into too much detail on nesting): Difference between tuple and set in mdx. Also, most of the links on that page are broken.

carl.hiass
  • 1,526
  • 1
  • 6
  • 26
  • Sets are data structures that do not contain any duplicate value. Tuples are similar to arrays but are immutable. – Akash Nov 29 '20 at 05:13
  • @Akash in MDX? Or are you just stating this from a general CS perspective? In MDX sets can have duplicate members, that's part of my question. – carl.hiass Nov 29 '20 at 05:14
  • I am stating from a general CS perspective. Thats why I commented and did not write an answer. – Akash Nov 29 '20 at 05:14
  • @Akash ok, then that's irrelevant. MDX even has a `DISTINCT` function that expects a set: https://learn.microsoft.com/en-us/sql/mdx/distinct-mdx?view=sql-server-ver15 – carl.hiass Nov 29 '20 at 05:15
  • @user2357112supportsMonica this is mdx though, not just general cs. For example if I would try and make a tuple where you mention I get this error: `Executing the query ... Query (4, 2) The 'Hierarchy' hierarchy appears more than once in the tuple. Run complete`. Basically a set **in mdx** has to have the same dimensionality and a tuple cannot. – carl.hiass Nov 29 '20 at 07:03

1 Answers1

3

MDX sets are an ordered collection of 0 or more tuples (note that a member is considered to be a tuple containing a single element) with the same dimensionality. Unlike a mathematical set, an MDX set may contain duplicates, it is more of a list of elements. More details here.

And perhaps as a refresh for MDX concepts here is a gentle introduction of MDX.

Marc Polizzi
  • 9,275
  • 3
  • 36
  • 61