Question

If Statement Calculated Member MS Analysis Manager MDX

Asked by: btrieve

I am trying to write a simple Iif statement for a cube in MS Analysis Manager. I want to check a level of a dimension and return measure values based on that criterion.

Here are a couple of attempts I have made. Although the syntax seems to pass, the results is always #ERR.

IIf( [Store_LWPA].[Opening Year Month].Dimension = 0   ,0,1)

IIf( [Store_LWPA].CurrentMember.[Opening Year Month] = 0   ,0,1)

I am brand new to this. Anyone have some direction for me?

IIf( [Store_LWPA].[Opening Year Month].Dimension = 0   ,0,1)
 
IIf( [Store_LWPA].CurrentMember.[Opening Year Month] = 0   ,0,1)

                                  
1:
2:
3:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-04-15 at 06:49:53ID24324132
Tags

MDX If Statement Calculated Member Analysis Manager

Topics

OLAP

,

SQL Server 2005

,

SQL Reporting

Participating Experts
2
Points
500
Comments
25

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Analysis Services: problems with calculated measures an…
    Two problems with calculated measures and members in a particular MDX query. The results of the query represent the performance of a set of Australia/New Zealand retail outlets at a given week in the quarter, with a summary line for the whole region. Here are the columns - ...
  2. Help required on MDX for Calculated Measures
    Hi, I use MS Analysis Services 2000 with service pack 3. I have 5 dimensions, Football, Hockey, Cricket, Tennis and Badminton. The members for each of these are TRUE and FALSE. A fact table joins the dimension tables for each of these by foreign keys. There are a number of ...
  3. OLAP MDX average problem
    Hello I have an MDX problem that need's solving, I'm new to OLAP so if anyone could point me in the right direction; it'd make my week. These are sample dimensions for the time dimension in the cube I'm building. The numbers represent the sum of a particular measure at each l...
  4. Nulls turning into zeros in Analysis Services 2000 Cube
    Hello Experts I have a fact table in SQL2000. There are some columns in the fact table used as measures in an Analysis Services 2000. In the SQL table, there are several rows that contain null values. In the cube, these appear as zeros. Is there a way I can tell Analysis s...
  5. MDX to consolidate dates with measures by columns
    I have a cube in SQL Server Analysis Services 2005 that has a structure like the following: Measures: Number of Tickets ([Measures].[Number of Tickets]) Dimensions: Submitted Date ([Submit Date].[Date].[Date]) Submitted By ([Submit By].[Name].[Name]) ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: garycrisPosted on 2009-04-15 at 07:00:57ID: 24148027

Try using IsGeneration() or IsLeaf()

IIf( IsGeneration([Store_LWPA].CurrentMember, 0) ,0,1)
 
OR
 
IIF(IsLeaf([Store_LWPA].CurrentMember) ,0,1)
                                              
1:
2:
3:
4:
5:

Select allOpen in new window

 

by: btrievePosted on 2009-04-15 at 07:25:05ID: 24148320

Here is what I want to do. If a level of my store dimension is >= a certain value, I want to bring back the sales dollars for that store/item combination.

For example, if [Store_LWPA]...[Open Year Month] >= 200701, bring back sales for all items sold at that store.

Then, in a second calculated member, I will need to do the same evaluation, but bring back comparable sales for that store/item from the previous year.

I am well versed in SQL but have never written an MDX query in my life. Any ideas, resources?

Thanks,

Ryan

 

by: garycrisPosted on 2009-04-15 at 07:59:14ID: 24148749

I need to understand your hierachy a little better.  Is 200701 a member in you hierarchy or is a value that you are loading?

Store_LWPA is your dimension, correct?
Is [Open Year Month] part of the Store_LWPA dimension or is it a member of a different dimension like Measures?

I'm thinking 200701 is a value loaded to the measure [Open Year Month] for different stores in the [Store_LWPA] dimension.  Am I correct?

 

by: btrievePosted on 2009-04-15 at 08:46:12ID: 24149376

Hi,

Thank you so much for your responses.

The dimension I have is Store_LWPA with levels [Store Code]...[Store Desc]...[Opening Year Month].

I added Opening Year Month simply so that I can use that in my formula. The value for Opening Year Month is assigned in SQL when I update the Dimension Table for Store_LWPA.

Thanks again for your help.

RMc

 

by: garycrisPosted on 2009-04-15 at 09:32:08ID: 24149967

I'm not sure if this is going to be the best way to do it.  You have set it up that 200701 is a member, therefore you are going to be limited in the way you evaluate it.  You can't say IF member is greater than or equal to another member and get the result you are looking for.  It would be kind of like saying IF member >= blue.  So blue evaluates but what is red?  Is red greater than or less than blue?

In Essbase, we have a concept of attributes, which can be text or numeric, I'm not sure in Analysis Services if there is something similar.  The way I would look at it is more along the road I was going down before where you set up [Open Year Month] as a measure and add it to your fact table.  Then you can evaluate the measure [Open Year Month] for any store and do your >= test.

If you just wanted to test for = then you could use the IS function
IIF(IS([Store_LWPA].CurrentMember, [200701]), 0,1)

I can't think of a way to evaluate the member for greater than, because as I mentioned before, it's really a text name and MDX does not support a CAST type function like in SQL where you could convert it to an integer for the evaluation.

I would make it a measure and then do something like
IIF( ([Store_LWPA], [Opening Year Month]).value >= 200701  ,0,1)

 

by: agandauPosted on 2009-04-15 at 10:24:25ID: 24150432

btrieve, could you whip up a sample output of the query you expect, along with whatever parameters the user entered at the time?  Nothing fancy, even just some text is good, along with some explanation of the user set parameters.

I agree with garycris that using the opening year month this way may not be most suitable.

I remember the biggest problem I had with learning MDX was trying to make it behave like SQL.  In SQL a where clause to filter out rows, because the select clause only defines what becomes the column headers.

So in MDX, you have to ask yourself, "what is the set of things I want on my row headers, and what is the set of things I want on my column headers".  Forget about filtering at first.  Maybe you're already well past this point with learning MDX (took me a while!).

In SQL you'd think of filtering rows where the yearmonth >= 200701, but in MDX you filter the rows by generating the set of all year months beginning with 200701 and ending with <some month in the future>.  The problem here is that dates won't really behave like dates unless they are stored in a time dimension, while this opening year month is an attribute of the Store Dimension.  

If I understand what you're trying to do correctly, I would generate a set of stores with the following code.  Note that the picture and the code have nothing to do with one another.


SELECT
 
   {[probably some measures]}
ON COLUMNS,
 
   FILTER(
      [Store_LWPA].Members, -- start with the set of all stores
      SUM(
         [Date].[All].[2007].[2007 Q1].[2007 01]      -- begin of range
         :                                            -- range operator
         [Date].[All].LastChild.LastChild.LastChild   -- end of range
      ) > 0.0
   )
ON ROWS
 
FROM
   [MyCube]
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:

Select allOpen in new window

 

by: agandauPosted on 2009-04-15 at 10:28:50ID: 24150475

Again, the code above and the picture are unrelated.  I left out a point I meant to make, that the filter is basically saying: give me the set of stores that have sales in 200701 or beyond.

This prompts me to ask, why do you need the opening year month?  Would the fact that store doesn't have sales before it opens be enough?  I guess now that I think about it my suggestion above relies on that notion.

Anyway, keep the questions or clarifications coming.

Hope this helps.
 

 

by: btrievePosted on 2009-04-15 at 11:09:50ID: 24150899

Thanks to both of you for these enriching responses.

The reason for this logic is that retail stores have to have been open for a minimum of 12 months to qualify as "comparable stores". This is to prevent newly opened stores from contributing unduly to this year's sales, which would lead to an inaccurate comparison with last year, when fewer stores existed.

My goal is to actually create two new columns, TYCompSales and LYCompSales. In intend to do this by evaluating the store's Opening Year Month with a critical value.

For now I intend to attempt Gary's suggestion. The problem is that I have never used MDX really, so I expect quite a challenge. Thanks again for your helpful comments.

 

by: btrievePosted on 2009-04-15 at 11:39:48ID: 24151199

Guys,

Can none of this be done with a case statement?

Ryan

 

by: garycrisPosted on 2009-04-15 at 12:07:02ID: 24151460

A CASE statement is the same as an IIF statement.  Albeit a lot cleaner, and my prefered method, but I still don't see how you do the comparison, whether it is an IIF statement or CASE.

 

by: btrievePosted on 2009-04-15 at 12:12:36ID: 24151533

Well, now I took your suggestion and put Opening Year Month as a measure in my fact table.

Couldn't I have a case like:

CASE [Measures].[Opening Year Month]
         WHEN [Measures].[Opening Year Month] > 200701 THEN [Measures].[DollarsSold]
 
         ELSE 0
end

 

by: agandauPosted on 2009-04-15 at 12:30:23ID: 24151705

If you mean to put that case statement in your SQL query, then yes.  You would then have a measure displaying only sales qualified for comparison, and you avoid having to complicate any MDX.  You'd simply pull the desired measure in your MDX query.

On the other hand (this is my preferred way) lets say you have several measures that require the same filtering.  One thing you can do, to avoid having to duplicate all those measures would be to take your case statement and have it return some pre-set fixed switched value:

CASE WHEN [Measures].[Opening Year Month] > 200701 THEN
    1
ELSE
    0
END as CompSalesFilterKey


Then create a small named query in your DSV and create a dimension from it.

SELECT 0 AS CompSalesFilterKey, 'Store First Year Sales'
UNION
SELECT 1 AS CompSalesFilterKey, 'Comparable Sales'

All your queries will have the option to filter any measure depending on whether the transaction happened in the first year of sales.  By default (unless you tinker with the all level of the dimension) all sales would show up, but you could filter out the first year sales by putting something like this in the where clause:

WHERE ([Comparable Sales Filter].[&1])  -- or whatever key value you choose.

 

by: agandauPosted on 2009-04-15 at 12:33:18ID: 24151731

Also out of curiosity, could the case statement read something like

CASE WHEN DATEDIFF("mm", Store Open Date, Sale Date) > 12

 

by: btrievePosted on 2009-04-15 at 12:49:40ID: 24151853

Hi,

Well, I would love to have solved all this in SQL, but my boss is opposed to it, and actually there is good reason for her opposition.

The amount of data is many millions  of records. We get the newest day's data at 7:30 in the  morning and we need the information available ASAP after that. To update two columns in SQL for multi-million rows would be quite time consuming. Also, because the comp store filter is based on the current moment in time, it would need to be recalculated at least weekly, possibly daily.

To your other question, the datediff will not work because of special logic the retail chain uses for there comps that I must replicate.

Ryan

 

by: garycrisPosted on 2009-04-15 at 13:10:35ID: 24152040

"Couldn't I have a case like:

CASE [Measures].[Opening Year Month]
         WHEN [Measures].[Opening Year Month] > 200701 THEN [Measures].[DollarsSold]
 
         ELSE 0
end"

Yes that is what I was thinking.
Not sure if you will have a syntax issue with the way you wrote it, I would write it as

CASE WHEN [Measures].[Opening Year Month] > 200701 THEN [Measures].[DollarsSold]
ELSE 0 END

 

by: btrievePosted on 2009-04-15 at 13:28:33ID: 24152223

Hi Gary,

Thanks for your suggestion about the case. Unfortunately your syntax does not work for me. It is telling me "token not valid"

RMc

 

by: agandauPosted on 2009-04-15 at 13:31:16ID: 24152251

That helps out a great deal, I can see why you'd want to attach the logic to the store rather than to the millions of rows.

Here's another thought, you could create add the Store Dimension a second time in the DSV and then use it as an additional fact table.  Add this table as the source for a new measure group, and then add only one dimension (the store dimension) and one measure (the numeric value of the opening year month).

The measure group should process pretty quickly (I'm guessing there aren't millions of stores) and it sounds like the all the data you need you've already added to the database.

Getting back to your original request, then the IIF statement in the calculated member would be:
   IIF(([Store_LWPA].CurrentMember, [Measures].[Open Year Month]) = 0, 0, 1)

 

by: garycrisPosted on 2009-04-15 at 13:39:33ID: 24152311

agandu jogged my memory, you can't just hit the measure, you have to hit the tuple, and you will probably need a value function

CASE WHEN ([Store_LWPA].CurrentMember, [Measures].[Opening Year Month]).value > 200701 THEN [Measures].[DollarsSold]
ELSE 0 END

 

by: btrievePosted on 2009-04-16 at 05:54:39ID: 24157056

Hi Guys,

Unfortunately that last syntax didn't work for me either, Gary.

Also, how do I write two case statements that will give me two new columns, TYSales and LYSales? Can this be done if the "time" dimension is not technically a time dimension but rather a standard dimension with time components?


 

by: btrievePosted on 2009-04-17 at 06:10:44ID: 24167343

Hi Guys,

I have the time dimension set up properly thanks to agandau. I was also able to get my "comparable stores" flag to work using a dimension table.

All I need now is the case statement to separate out the columns for TYSales and LYSales.

Any advice?

 

by: agandauPosted on 2009-04-17 at 09:47:00ID: 24169654

I'm lost - let's back up a bit here.  Lots of suggestions have been made and I'm not clear what you've already tried.

Can you provide a small sample of the data behind the store dimension?

 

by: btrievePosted on 2009-04-17 at 10:58:01ID: 24170347

Sure, but I really just need a case statement that will say

Case when Year = year(getdate()) then [measures].[Dollars Sold] else null

for TY Sales

and

Case when Year (time dimension) = year(getdate())-1 then [measures].[Dollars Sold] else null

I am mixing in SQL because I am lost with the MDX.

Can you help or do you need more information?

 

by: agandauPosted on 2009-04-17 at 12:21:27ID: 24171143

I know a case statement is what you'd like but what you're looking for wouldn't really be a case statement in MDX.  Instead your measure will be constructed from a tuple.  I wish I had access to my Adventureworks analysis database to cook up an example for you right now.

Here's some info on getting the current date into an expression (written by Mosha Pasumanski, one of the founding fathers of the MDX language):

http://www.sqljunkies.com/WebLog/mosha/archive/2007/05/22/current_date_mdx.aspx

I hope the following doesn't sound like a lecturing tone, but you did say you're new to MDX:  In case you're not familiar with what a tuple is, in the code it's a parentheses wrapped, comma delimited list of members from every dimension in the cube.  What it returns is a measure value residing at the cross section in the cube of those members.  The confusing thing at first is that most tuples are not written as though they contain a member from every dimension, because in the code, if a dimension isn't represented, then the CurrentMember for that dimension is assumed.

All I think you're looking for is a measures defined as tuples:
TYSales = ([Time].[All].[2009], [Measures].[Sales Dollars])
LYSales = ([Time].[All].[2009].PrevMember, [Measures].[Sales Dollars])

Now the trick is to get rid of the explicit reference to 2009 removed, and I think the article in the link above can help you out with that.

 

by: btrievePosted on 2009-04-20 at 07:14:17ID: 24184774

Hey,

I really like your comments. I think this is the solution but I am getting a syntax error.

I am inserting your statement into a calculated member in Analysis Manager and it tells me it cannot find the dimension member in a name binding function. What does this mean?

 

by: btrievePosted on 2009-04-20 at 08:09:00ID: 31570441

Thank you, I have it working. You are a genius!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...