Home > Articles > Data > SQL Server

  • Print
  • + Share This
Like this article? We recommend

About Creating a Calculated Cell

We can create calculated cells with the Calculated Cell Wizard or the Cube Editor, both of which are accessed from within Analysis Services. Calculated cells originated in this way can be created with a global scope, meaning that they will be "permanently" available to all information consumers who browse the cube, much like a calculated member created within the cube superstructure.

We can also create calculated cells with a session scope, meaning that they are available only to MDX queries executed within the session in which they are born. These calculated cells are essentially creatures of the MDX query, and they provide a higher level of flexibility for client applications (among other uses).

We will examine the steps involved in creating calculated cells in each of the two ways and then we will focus on the calculated cell in the MDX query for the remainder of the lesson.

Creating a Calculated Cell with the Calculated Cells Wizard

Creating a calculated cell within Analysis Services will serve to introduce us to general concepts from the perspective of the Calculated Cell Wizard, in which the process of creation is largely guided and user-friendly. This brief overview with the wizard will thus afford us an opportunity to focus on the attributes and characteristics of the calculated cell before getting involved in the MDX syntax.

Creating the Basic Calculated Cell

We will start Analysis Services, navigating to the Warehouse cube, which is supplied as a sample when we install Analysis Services.

  1. Start Analysis Manager (Start, Programs, Microsoft SQL Server, Analysis Services, Analysis Manager).

  2. Expand the Analysis Servers folder by clicking the + sign to its left.

  3. Expand your server (typically named the same as your PC, but determined by the installation/setup) and then expand the FoodMart 2000 database (see Figure 1).

    Figure 1Figure 1 Navigate to the FoodMart2000 database in Analysis Manager.

  4. Expand the FoodMart2000 database by clicking on the + sign to its left.

  5. Expand the Cubes folder (as shown in Figure 2) by clicking the + sign to its left.

The cubes appear, similar to those shown in Figure 2.

Figure 2Figure 2 Sample cubes provided with the Analysis Services installation.


  1. Right-click the Warehouse cube; then click Edit from the context menu.

    The Cube Editor appears.

First, let's set the stage for the steps to come. We will be performing an analysis that focuses on individual surrounding warehouses, so let's set up the data viewing pane to conform to our needs.

  1. Click the Data tab on the right half of the screen.

  2. Drag the Warehouse dimension to the rows area (the left column of the lower pane section), dropping the icon onto the current column heading.

  3. Ensure that the 1997 Time dimension is displayed in the filter box atop the preview pane, indicating that we are filtering on 1997.

  4. Double-click the USA Country member to expand the hierarchy and show the underlying states.

  5. Double-click the State Province column heading to drill down to display members of the City level.

  6. Double-click the City column heading to drill down to display individual Warehouse Names.

  7. Scroll over so that the Warehouse Cost measure appears alongside the individual warehouse members.

    The Cube Editor preview pane should appear (as partially shown in Figure 3).

    Figure 3Figure 3 Cube Editor preview pane (partial view) after adjustments.

  8. Select Insert from the top menu.

  9. Click Calculated Cells on the Insert menu (as shown in Figure 4).

    Figure 4Figure 4 Select Calculated Cells to initialize the Calculated Cells Wizard.


    The Calculated Cells Wizard Welcome dialog appears, as shown in Figure 5.

    Figure 5Figure 5 The Calculated Cells Wizard welcome dialog box.


  10. Click Next.

    The Define the Calculation Subcube dialog box appears.

Let's focus now on the capabilities of the calculated cell to perform exception highlighting. For this example, we will create a calculated cell that highlights all USA warehouse locations with Warehouse Costs exceeding $11,000 for 1997. The first step of defining the new calculated cell is to define the range of cells in the cube, also known as the subcube (or cube region) upon which the calculated cell will act.

  1. Highlight/select the Warehouse dimension from the list on the left side of the Calculation Subcube dialog box.

  2. From the Members Set drop-down selector on the right side of the dialog box, select A single level, as shown in Figure 6.

    Figure 6Figure 5 The Calculated Cells Wizard welcome dialog box.


  3. Expand the Warehouse dimension tree, and select Warehouse Name. The dialog box appears as shown in Figure 6.

  4. Click Next.

    The Define the Calculation Condition dialog box appears.

At this stage, the wizard prompts for the calculated cell condition. We want to put highlighting in place for warehouse locations with Warehouse Costs exceeding $11,000 for 1997. To establish the condition for the application of highlighting, we will input the statement at this stage.

  1. Click the second radio button (Apply the Calculation Formula to Cells in the Calculation Subcube that Meet the Following Conditions) to select it.

  2. Enter the following into the MDX Expression text box:

    CalculationPassValue((Warehouse.CurrentMember, 9
    [Warehouse Cost]), 0) > 11000

Our condition formula uses the CalculationPassValue() function to ascertain the value of the cell before we apply the calculated cell. We are using this approach as a means of preventing the expression from being recursive, or referencing itself, as would normally be the case in a situation like ours (where the condition expression reads the value of the current cell, which itself references the calculation formula again). Because multiple passes are required for evaluation of MDX expressions, and because we know that evaluations of calculated cells will occur beyond pass 0, we tell Analysis Services to stop the evaluation at pass 0 (by placing 0 in the second argument position) and return the associated value. This mainly serves to prevent the expression from referencing itself ad infinitum, as if in a loop.

The completed Define the Calculation Condition dialog box appears, as shown in Figure 7.

Figure 7Figure 7 The completed Define the Calculation Condition dialog box.


  1. Click Next.

    The Define the Calculation Formula dialog box appears.

At this point, we are prompted to enter the expression for the calculation itself. The outcome of this formula will be the value that is assigned to the cells within the selected range after evaluation of those cells via the condition we have assigned the calculated cell. Remember that the condition is a logical expression, and therefore evaluates to True or False; it is applied to every cell in the range defined in the calculation subcube. For any cell for which the condition evaluates to True, the result of the calculation formula applied to that cell is returned when the cell is queried. A false condition, by contrast, returns the actual value of the cell when it is queried. (Much of the power in calculated cells is that no real alteration of the data itself is taking place).

  1. Enter the following into the MDX Expression text box:

    CalculationPassValue(Warehouse.CurrentMember, 0)

    The completed Define the Calculation Formula dialog box appears, as shown in Figure 8.

    Figure 8Figure 8 The completed Define the Calculation Formula dialog box.


In this example, we do not provide a surrogate value for cells that meet the condition, but use the condition as a basis for the application of exception highlighting only. Therefore, the address of the current cell is appropriate. We use the CalculationPassValue() function to prevent the expression from referencing itself once again (via the same logic we used in the calculation formula in the last step.

  1. Click Next.

We arrive at the Finish the Calculated Cells Wizard dialog box. We provide the name Warehouse Cost Subanalysis Scope, to define a list of warehouses whose level of costs exceeds the threshold of our scope for further examination. We see a summary of the parameters we have assigned through the wizard for the calculation subcube (defaults were assigned for dimensions that we did not specify). In addition, we see a confirmation that the calculation condition has been specified.

    The Finish the Calculated Cells Wizard dialog box appears, as shown in Figure 9.

    Figure 9Figure 9 The completed Finish the Calculated Cells Wizard dialog box.


  1. Click Finish.

At this point in the calculated cells creation process, we have a new calculated cell that has no display criteria. We should see the calculated cell Warehouse Cost Subanalysis Scope in the left side of the Cube Editor within the appropriate folder of the tree pane (see Figure 10).

Figure 10Figure 10 The new calculated cell appears in the tree.

Setting Properties for the Calculated Cell

We now need to set the display properties for the calculated cell in a manner very similar to the way in which we set properties for the calculated members.

  1. Click once to select the Warehouse Costs to Subanalyze calculated cell.

  2. Expand the Properties pane in the lower tree pane.

  3. Click the Advanced tab.

    The Properties pane—Advanced tab—appears, as shown in Figure 11.

    Figure 11Figure 11 The Properties pane—Advanced tab.


The ForeColor and BackColor cell properties are used to store color information for the text and the background of a cell, respectively. The color and hue are defined in these properties boxes using an RGB value (the Microsoft Windows operating system red-green-blue format).

Any color in the spectrum exists at some intersection point of the basic colors (or as a "pure" color), a few common examples of which are shown in the simple illustration shown in Figure 12.

Figure 12Figure 12 Color definitions from the perspective of RGB.

Without going too far into the details of the nature of the RGB system, let's say that a normal color is represented by a number between 0 and 16,777,215. In our example, we can define our color combination by selecting the hue (a number ranging between 0 and 255, with 255 being the brightest and 0 being the darkest within the range) and plugging that hue into the respective color variables (R, G, or B) in the following formula I derive. The resulting number is the color value, which is placed into the appropriate ForeColor and BackColor cell property box on the Advanced tab.

To simplify, all we really need to know is that the numerical components for color value are represented as Red, Green, and Blue (assigned R, G, and B, respectively) in the following formula.

Color Value	 =	(R * 256 0) + (G * 256 1) + (B * 256 2)
             =	1(R) + 256(G) + 256 2 (B)
             =	R + 256G + 65536B

Eight sample colors and their corresponding RGB hue values appear in Table 1.

Table 1 Eight Sample Colors with their Respective RGB Hue Values

Color

RGB Hue Values

Red

255, 0, 0

Green

0, 255, 0

Blue

0, 0, 255

Cyan

0, 255, 255

Magenta

255, 0, 255

Yellow

255, 255, 0

White

255, 255, 255

Black

0, 0, 0


Let's say we want to customize our exception highlighting ForeColor to have a magenta appearance. We would derive the color value as follows:

Color Value	=	R + 256G + 65536B
     		=	255 + 256 (0) + 65536 (255)
	    	=	255 + 0 + 16,711,680
	    	=	16,711,935
  1. Type the number 16,711,935 into the ForeColor property box of the Advanced tab.

Now, let's derive the needed setpoint to make our BackColor property equal black. Easy enough, for we can see from the table above that all setpoints are zeroes.

Color Value	=	R + 256G + 65536B
    		=	0 + 256 (0) + 65536 (0)
	    	=	0

The setpoint, as we see, is zero.

Why, then, should we have to type anything into the BackColor property box? Although it seems that "nothing," or null, might equal "zero" in a field, the default is set for white as the color in this case, simply because this would be the most common desire in presentation.

  1. Place a zero in the BackColor property box of the Advanced tab.

We can also set other display characteristics on the Advanced tab. The FontFlags property, for example, can have the basic setpoints, or a combination of the setpoints, shown in Table 2.

Value

Description

1

Bold

2

Italic

4

Underline

8

Strikeout


We can add numbers together to achieve combinations of their effects. Examples might include the value 5, which represents the combination of bold and underline font effects, and the value 3, which represents the combination of bold and italic.

  1. Place the number 3 in the FontFlags property box.

The FontName property allows us to set the font of the displayed calculated member, whereas the FontSize property makes it possible to customize the font size of the calculated member. We will leave these at the default values.

The Format String property enables the customization of the format for displaying cell values. The set of possible values within the Format String property is substantial; a user-defined format expression for numbers can have anywhere from one to four sections separated by semicolons, and its values can be different—depending on the data types involved (numeric, string, etc.). For our example, we will be dealing with a numeric value, Warehouse Cost, so we can use up to four parameters, in the format string value that we assign, to instruct Analysis Services how to handle positive numbers, zero values, negative numbers, and null values, in that order. Although potentially confusing, the option also exists to supply fewer than the four parameters: The values given will then apply to more than one of the four standard groups, creating a composite parameter, as it were. An example is illustrated in our next step.

  1. Place the following two-parameter numeric format string in the Format String property box:

    $#,##0.00;($#,##0.00)

The above example has two sections: The first section dictates the format for positive values and zeros; we have included the dollar ($) sign to indicate that we wish to have it precede the number in the cell, the # characters to act as digit placeholders, and the thousand separator (,) and decimal placeholder (.) information in this section. The second section, in our example, defines the format for negative values. We have selected parentheses as the negative number indicator (instead of the negative sign). The other characters act as they do in the first section.

As we have discussed, the Format String property options are voluminous and far-reaching. For more information on them, as well as the other properties', setpoints, see the Books Online that were installed with the Typical MSSQL 2000 Analysis Services installation; or that can be found on the original installation CD, on the Microsoft website, and/or from other sources.

The Properties pane—Advanced tab with our additions appears, as shown in Figure 13.

Figure 13Figure 13 The Properties pane—Advanced tab with additions.

  1. After filling in the property boxes above, press the Enter key (clicking outside the Properties pane also refreshes the Data Viewing pane).

The partial results set returned in the Data Viewing pane should resemble those shown in Figure 14.

Figure 14Figure 14 Partial results in the Data Viewing pane, with calculated cell effects.


We see that the new calculated cell has accurately performed its work, highlighting those Warehouse Names where the Warehouse Cost exceeds our $11,000 threshold. We can almost certainly go further in determining information consumer requirements in our own working environments, such as to ascertain whether consumers would want to see highlighted "rollups" values (as a means of management and/or analysis by exception at a higher level), for totals whose membership contained highlighted exceptions, and so forth. In addition, there are many other setpoints that can be used for sophistication and flexibility in our displays. (Books Online serves as a great place to start exploring these powerful options.)

  1. Save the work as desired.

  • + Share This
  • 🔖 Save To Your Account

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020