Download presentation
Presentation is loading. Please wait.
Published byLoreen Simmons Modified over 6 years ago
1
Module 11: Introduction to DAX Module 11 Introduction to DAX
Course 10778A Module 11: Introduction to DAX Module 11 Introduction to DAX
2
Module 11: Introduction to DAX
Course 10778A Module Overview Module 11: Introduction to DAX DAX Fundamentals Using DAX to Create Calculated Columns and Measures in a Tabular Data Model
3
Lesson 1: DAX Fundamentals
Course 10778A Lesson 1: DAX Fundamentals Module 11: Introduction to DAX Overview of DAX DAX Functions DAX Syntax and Data Types Aggregations Context DAX Queries
4
Module 11: Introduction to DAX
Course 10778A Overview of DAX Module 11: Introduction to DAX DAX is a formula-based language for building business logic and queries in tabular data models: Calculated columns Measures Queries Its syntax is similar to Microsoft Excel formulas: It uses functions, operators, and values It is easy to use and already familiar to information workers It differs from Excel formulas in key ways: It is designed to work with relational data, not data ranges It includes more advanced functionality There are new functions to expand DAX
5
Module 11: Introduction to DAX
Course 10778A DAX Functions Module 11: Introduction to DAX Text functions Information functions Filter and value functions Logical functions Mathematical and trigonometric functions Statistical and aggregation functions Date and time functions Time intelligence functions For more information about the Data Analysis Expressions (DAX) function reference for Microsoft® SQL Server® 2012, see the “DAX Function Reference” at
6
DAX Syntax and Data Types
Course 10778A DAX Syntax and Data Types Module 11: Introduction to DAX DAX formulas start with the equal sign (=) followed by an expression Expressions can contain functions, operators, constants, and references to columns Column references: Fully qualified name: Unqualified name: Measure names must be enclosed in brackets DAX uses eight data types For the full syntax specification, see “DAX Syntax Specification for PowerPivot” at 'table name'[column name] [column name]
7
Module 11: Introduction to DAX
Course 10778A Aggregations Module 11: Introduction to DAX Summarize underlying detailed data for analysis Use automatic aggregation for simple calculations: SUM COUNT MIN MAX AVERAGE Create a measure for more complex aggregations SUM('Reseller Sales'[Sales Amount])
8
Module 11: Introduction to DAX
Course 10778A Context Module 11: Introduction to DAX A DAX measure or calculated column defines a field that you can use in a PivotTable table or a PivotChart chart The exact values that appear in PivotTable tables and PivotChart charts vary with context: Row context Query context Filter context
9
Module 11: Introduction to DAX
Course 10778A DAX Queries Module 11: Introduction to DAX Client applications, such as the Power View reporting tool, issue DAX queries You can write queries manually by using the DAX query language You can filter, order, and summarize results EVALUATE( FILTER('Reseller Sales', 'Reseller Sales'[OrderDateKey]> ))
10
Module 11: Introduction to DAX
Course 10778A Lesson 2: Using DAX to Create Calculated Columns and Measures in a Tabular Data Model Module 11: Introduction to DAX Calculated Columns Measures Multiple Relationships Time Intelligence Dynamic Measures
11
Module 11: Introduction to DAX
Course 10778A Calculated Columns Module 11: Introduction to DAX Named columns that are populated by using a DAX formula Create calculated columns in the Data View window of a PowerPivot for Excel workbook: Add a new column Provide a name Enter a DAX expression in the formula bar A value is calculated for each row in the table when the calculated column is created Use calculated columns in PivotTable tables, PivotChart charts, slicers, and measure definitions =CONCATENATE('Employee'[First Name], CONCATENATE(" ", 'Employee'[Last Name]))
12
Module 11: Introduction to DAX
Course 10778A Measures Module 11: Introduction to DAX Named formulas that can contain sophisticated business logic: Implicit measures Explicit measures Create explicit measures in two places: The PowerPivot Field List in an Excel worksheet The Measure Grid in the table view in the PowerPivot window Use measures in PivotTable tables and Pivot Chart charts IF([Previous Year], ([Sum of Sales Amount] – [Previous Year])/[Previous Year], BLANK())
13
Demonstration: Creating and Using Measures and Calculated Columns
Course 10778A Demonstration: Creating and Using Measures and Calculated Columns Module 11: Introduction to DAX In this demonstration, you will see how to: Create a calculated column Create a measure Use measures and calculated columns in PivotTable tables and PivotChart charts Use measures to create different groupings of data Task 1: Create a calculated column Ensure that the MIA-DC1 and MIA-SQLBI virtual machines are both running, and then log on to MIA- SQLBI as ADVENTUREWORKS\Student with the password Pa$$w0rd. Then in the D:\10778A\Demofiles\Mod11 folder, run Setup.cmd as Administrator. In the D:\10778A\Demofiles\Mod11 folder, double-click the Demo.xlsx file. In the Demo workbook, click the PowerPivot tab, and then on the PowerPivot ribbon, click PowerPivot Window. In the PowerPivot window, click the Geography tab. In the Geography table, scroll across to the last column, double-click Add Column, type Full Location Name, and then press Enter. In the formula bar above the Geography table, type the DAX formula in the following code example, and then press Enter. =CONCATENATE([State or Province Name], CONCATENATE(“, “,[Region Name])) Right-click the State or Province Name column header, and then click Hide from Client Tools. Task 2: Create a measure In the PowerPivot window, in the upper-left corner, click the Switch to Workbook button. Click the Add Measure Demo tab, and then click PivotTable1. In the PowerPivot Field list, click Refresh if notified that PowerPivot data was modified. In the PowerPivot Field List, right-click Reseller Sales, and then click Add New Measure. In the Measure Settings dialog box, in the Measure Name (all PivotTables) field, type Total Profit. In the Formula field, type the DAX formula in the following code example, and then click Check Formula: =SUM(‘Reseller Sales’[Sales Amount]) – SUM(‘Reseller Sales’[Total Product Cost]) In the Category field, click Currency, and then click OK. Task 3: Use measures in a PivotTable table and a PivotChart chart When the you create the Total Profit measure, it should automatically appear in the PivotTable1 table. If it does not, in the PowerPivot Field List, expand Reseller Sales, and then select Total Profit. In Reseller Sales, select Sales Amount. Expand Product, drag Category to the Row Labels area, and then release it.
14
Multiple Relationships
Course 10778A Multiple Relationships Module 11: Introduction to DAX Tabular data models support multiple relationships between tables Only one relationship is active at a time The active relationship is used by default in DAX formulas The USERELATIONSHIP function enables you to select the relationship that you want to use for a specific formula =CALCULATE(SUM(Reseller Sales[Sales Amount]), USERELATIONSHIP(Reseller Sales[ShipDateKey],Date[DateKey]))
15
Demonstration: Using a Specific Relationship in a Measure
Course 10778A Demonstration: Using a Specific Relationship in a Measure Module 11: Introduction to DAX In this demonstration, you will see how to: Use the USERELATIONSHIP function to specify the relationship to use in a formula Task 1: Specify the relationship to use in a formula In the Demo workbook, click the PowerPivot tab, and then on the PowerPivot ribbon, click PowerPivot Window. On the ribbon, in the View group, click the Diagram View button. Rest the cursor arrow on each of the three lines between the Reseller Sales table and the Date table, one at a time. The lines represent the relationships between the tables. In the PowerPivot window, in the upper-left corner, click the Switch to Workbook button, click the Multiple Relationships Demo tab, and then click anywhere in PivotTable1. In the PowerPivot Field list, click Refresh if notified that PowerPivot data was modified. In the PowerPivot Field List, expand Reseller Sales. Right-click Sales With Ship Date, and then click Edit Formula. In the Measure Settings dialog box, review the formula, and then click Cancel. Drag Sales With Ship Date to the Values area in the PowerPivot Field List, and then release it. In the PowerPivot Field List, expand Date, drag Calendar Year to the Row Labels area, and then release it. Close Demo.xlsx and do not save changes.
16
Module 11: Introduction to DAX
Course 10778A Time Intelligence Module 11: Introduction to DAX Compare data from one time period against equivalent data from a different time period The tabular model should contain a separate table that contains only date information The date table should have a continuous range of dates without any gaps The column in the date table that uses the date data type should use day as the lowest level of granularity Mark the table as Date Table to use time intelligence functions against that table Use time intelligence functions to build measures CALCULATE([Sum of Sales Amount], DATEADD('Date'[FullDateAlternateKey], -1, YEAR))
17
Module 11: Introduction to DAX
Course 10778A Dynamic Measures Module 11: Introduction to DAX Calculate different values for each row in a PivotTable table: Create a linked table that contains the input values for the dynamic measure Use the HASONEVALUE function to check that there is a single input value for each row Use conditional logic to apply different calculations to each row based on the input value IF([Check Single Values)], SWITCH(VALUES('Time Period'[Period]), "Current Year", [Sum Of Sales Amount], "Previous Year" [Previous Year], "YOY Growth" , IF(NOT(ISBLANK([Previous Year])), [Sum of Sales Amount] – [Previous Year], BLANK())), BLANK())
18
Module 11: Introduction to DAX
Course 10778A Lab Scenario Module 11: Introduction to DAX As a senior business analyst at Adventure Works Cycles, you want to perform some detailed analysis of the data in tabular data model. Specifically, you want to: View the full name of each employee and aggregate sales data based on the reporting hierarchy of sales employees and managers View the sales contribution of each sales employee and manager as a percentage of the total sales achieved View year on year sales growth as a percentage View sales values for the current year and previous year, and show the year on year growth as a monetary value Students will perform the lab in the role of a data analyst in the Adventure Works Cycles company, and: Create calculated columns in a PowerPivot Excel workbook. Create measures. Upload the Power Pivot workbook to SharePoint and view it there. Use the PowerPivot workbook in SharePoint as a data source for an Excel PivotTable Point out that the instructions in the lab are deliberately designed to be high-level so that students need to think carefully about what they are trying to accomplish and work out how best to proceed for themselves. Encourage students to read the scenario information carefully and collaborate with each other to meet the scenario requirements. Remind students that if they find a particular task or exercise too challenging, they can find step-by-step instructions in the lab answer key.
19
Lab 11: Creating Calculated Columns and Measures by Using DAX
Course 10778A Lab 11: Creating Calculated Columns and Measures by Using DAX Module 11: Introduction to DAX Exercise 1: Creating Calculated Columns Exercise 2: Creating Measures Exercise 3: Using Time Intelligence Exercise 4: Creating a Dynamic Measure In this lab, students will create calculated columns, use calculated columns to create a hierarchy, create and reuse measures, create a measure that uses time intelligence, and create a dynamic measure. Exercise 1 In this exercise, students will create a calculated column by using the CONCATENATE function. Then, they will use the PATH, PATHITEM, and LOOKUPVALUE functions to create calculated columns to support a parent-child relationship hierarchy. Finally, they will use the hierarchy in a PivotTable table. Exercise 2 In this exercise, students will create a measure that uses the CALCULATE and ALL functions to calculate total sales for all employees. Then, they will reuse this measure to calculate the percentage of sales per employee. Finally, they will use these measures in a PivotTable table and add conditional formatting. Exercise 3 In this exercise, students will mark a table as Date Table and use the DATEADD function to create a measure. Then, they will reuse this measure to calculate year-on-year growth. Exercise 4 In this exercise, students will create a linked table and use the HASONEVALUE function to create a measure that checks input values. Then, they will use the IF, SWITCH, VALUES, NOT, ISBLANK, and BLANK functions to create a dynamic measure. Logon information Virtual machine MIA-SQLBI User name ADVENTUREWORKS\Student Password Pa$$w0rd Estimated time: 60 minutes
20
Module Review and Takeaways
Course 10778A Module Review and Takeaways Module 11: Introduction to DAX Do you or your colleagues use Excel formulas? What limitations have you encountered? What features of DAX might help you to overcome these limitations? Do you have any table relationships for which the ability of DAX to support multiple relationships might be useful? Will time intelligence functionality be useful to you? What kinds of analyses might you want to perform? Review Questions Point the students to the appropriate section in the course so that they are able to answer the questions presented in this section. Some guidance for discussing the answers to the questions is included below. Do you or your colleagues use Excel formulas? What limitations have you encountered? What features of DAX might help you to overcome these limitations? Answers will vary depending upon individuals and their experiences. Do you have any table relationships for which the ability of DAX to support multiple relationships might be useful? Answers will vary depending upon individuals and their experiences. Suggest common multiple relationship scenarios such as relationships that involve Date tables. Will time intelligence functionality be useful to you? What kinds of analyses might you want to perform? Answers will vary depending upon individuals and their experiences. Try to match students’ suggestions to the relevant time intelligence functions.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.