August 2003 MDX Puzzle Solution

Downloads
39705.zip

Problem: How would you write a query to find the top 10 customers based on unit sales who aren't single and female? Can you do it without listing any of the three other combinations (i.e., single male, married male, and married female)?

Solution: As Listing A shows, I answered this problem by filtering out the single, female customers before ranking the remaining customers with a TOPCOUNT() function. As you can see in the FILTER() function's second parameter, I used the virtual dimensions Marital Status and Gender, along with Unit Sales, to determine whether a particular customer in the top 10 was single and female. To be sure I had the right customers, I also created measures to return the marital status and gender for each displayed customer. I included those measures on the result's columns along with Unit Sales.

Discuss this Article 1

Jeff Jones (not verified)
on Oct 3, 2003
In reviewing this solution, the code to filter only those customers that are not single or female doesn't make sense. When I change the filter condition to "> 0" from '= 0" and drop the Topcount, I see only customers that are single and female. (Kinda what I would expect). Then change it back to "> 0" and I see the other possible combinations (Married and Female or Single and Male, etc) and single and female if the unit sales is null. Doesn't make sense. Can someone give me a better explanation for this behavior. Thanks, Jeff

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottOur Experts will show you:
• Common SQL Server
Problems
• Best Practices for T-SQL
• SQL Server Integration
Services
• Database Development

Come See Mike Otey & Tim Ford in Person!

Early Registration Now Open

From the Blogs
May 9, 2013
blog

My ISO 8601-Compliant Signature 2

My family recently just "officially" announced that we're in the process of adopting a child from South Africa. We're quite excited, of course, but there's a ton of paperwork to do—along with the need for gobs of signatures....More
May 8, 2013
blog

Use SSIS for ETL from Hadoop

In this blog post, Mark Kromer walks you through using SSIS as a way to use ETL techniques using Microsoft's Hadoop on Windows (HDInsight) as a source using Hive connectors...More
Vision road sign
May 6, 2013
blog

Cheaters Never Win, Even in TPC Benchmarks

In this portion of the series on database benchmarking, I want to tell you about one of my favorite aspects of the TPC benchmarks – CHEATING....More
SQL Server Pro Forums

Get answers to questions, share tips, and engage with the SQL Server community in our Forums.