Sum Function in MDX when using SSAS

2. April 2011 15:15

SSAS has quite a few functions that have different purposes and can make a lot of potential calcuatlions a lot easier.  A recent issue I was faced with is I had a new measure group to build based off a fact table.  This measue group had quite a few Calculated Members that needed to be built in order to complete the all the measures that would be needed.

 

I came across an interesting problem where I needed to use a measure from a seperate measure group, and apply a dimension to the measure to get a total. To get down to details, I needed the Gross USD (United States Dollars), only when applied by dimenions of food and beverages...not when involving merchandise.   Now, the identifier for Food, Beverages, and Merchandise were all part of one dimension named "Family Grouping".  So I knew in the end I needed the sum of Gross USD, and I needed the value of it only against Food and Beverage. 

 

So, at first I thought, maybe I would use the Scope Function, but that seemed like it wasn't really answering my issue, as the SCOPE function seemed to apply values across a particular range of a given measure. 

No, what I wanted was to be sure that whenever I got my GROSS USD total, it always gave me the amount when directly related to my particular dimensions...and the answer to that was to use the SUM function.

So my first stab at the sum function was to use code similar to this in my calculated memeber, minus all the other "who-ha".

SUM({null:[Dim Type Grouping].[Type Grouping].&[2]}, [Measures].[Gross USD])

What this did is it gave me the sum of the Measure Gross USD across my Dimension of type grouping 2...but I was surprised to see it included the type Grouping 1 as well.  This wasn't what I wanted as the the type grouping of 1 had no bearing on my calculated member that I was trying to achieve.  The Null statment previous my Dimension is what caused it to pull in my first dimension as well.  Admittedly I still need to figure out why that is the case.


So to fix my calculation I made a slight modificaiton, and got this.

SUM({[Dim Type Grouping].[Type Grouping].&[2]}, [Measures].[Gross USD])

 

The query above in my calculated member, properly returns only the Gross USD when related to the Dimension of typeGrouping 2.

In the end, the Sum function is quite powerful, and can be used in a variety of ways, and should not be confused with the AGGREGATE function, which works a bit differently.

 

Sending Email or SMS in Windows Phone 7

16. March 2011 19:54

I'm working on my own application for Windows Phone 7, like many people are.  Part of the requirements I've set for my application is to let the users send the context of what they are working on to other people via SMS or Email.  The reason being, that I'm not making my application work on Android or Iphone, but if the user can at least do their work in my app, and send the results to other users, it may be beneficial.

To send either an SMS or Email were going to use the same Namespace.

using Microsoft.Phone.Tasks;

Now, lets look at how easy it is to send an email from your Silverlight WP7 application.

 

private void btnSend_Click(object sender, RoutedEventArgs e)
        {
            EmailComposeTask ect = new EmailComposeTask();

            ect.Body = "A really great source that provides the body for your email would go here";
            ect.To = "somebody@email.com";
            ect.Subject = "WP7 Email";

            ect.Show();
        }

The code above is obviously linked directly to a button click for simplicity of example.  We've instantiated an EmailComposeTask, preset some values, and then used the Show method to the launch the email application.  Provided the user has set up at least one or more email accounts, they will go through email task screens they at this point are most likely very familiar with.  Prompted to choose an email account, and potentially just hit send based on the values you provided before launching the email application.  

 

Sending an SMS is part of the same namespace and follows the same basic steps.

private void btnSendText_Click(object sender, RoutedEventArgs e)
        {
            SmsComposeTask sct = new SmsComposeTask();

            sct.Body = "A great message that takes into account 160 character concepts goes here";
            sct.To = "1235554567";
            sct.Show();
        }

 

 Again, same general flow, task is instantiated, we can set some basic values, and then launch the corresponding task by using the "Show" method.  This, like the email task, requires user interaction to be completed.  This means they can also change the values preset by your application prior to sending, something to keep in mind when deciding to use these tasks.

 

Considering how simple these tasks where, I encourage you to review the many other tasks in the Microsoft.Phone.Tasks namespace.  You'll see a lot of features have been simplified for you via these tasks, so please familiarize yourself with them before potentially reinventing the wheel.

Starting to Blog

3. March 2011 22:36

OK, here it is, a blog. I've finally decided to give it a whirl and start putting my concepts to the virtual paper we call the web.  I'm .NET programmer at heart, but of course, like all programmers, I dabble in a lot of different things.   My guess is that eventually I'll post a few helpful tidbits on this blog that might help another programmer through a tuff time.  Or even better, I'll post how to do something in some horrendous manner, and it'll bring all the village programmers out with their torch and pitchfork. 

I'd like to say I'll do my best not to delete posts or comments, but who knows.  I'm guessing that it'll take awhile for anyone to even see this site. A bit more info about myself, I've been programming for a questionable amount of years.  Some of the things I've done, do and will post on are:

  • SSRS, SSAS, SSMS, SSIS, and any other things that make you sound like a snake.
  • Sharepoint 2007...a more recent venture.  Wish I could say it was 2010
  • Silverlight since the 2.0 days.. 1.0 didn't win my attention.
  • Windows Phone 7, nothing on the market yet, but soonish.
  • XNA, fun stuff.
  • C# and VB.Net I prefer C# though and most of my code will be in C#.
  • WCF... get your bindings warmed up.
  • WPF
  • Expression Blend, Sketchflow, Web, Design, Encoder...and bears oh my.
  • Office 2007,2010
  • Ancient technologies like 1.1, VB6.. I'll avoid these like the plague but they are none the less a part of the arsenal.

I'm sure I'll chat about other things I do, eventually.  I consider myself to be long winded at times.  Fun Fun.  So if your reading this, welcome to the site, I probably sent you the link myself.

About the author

My name is Brian, I'm A .NET programmer for Hard Rock. Causing trouble one line of code at a time.

Month List