Download presentation
Presentation is loading. Please wait.
1
Introduction to Tabular Data Models
Julie Koesmarno | Consultant, MsSQLGirl Patrick LeBlanc | Senior Technical Specialist, Microsoft
2
04 | Querying with DAX Julie Koesmarno | Consultant, MsSQLGirl
Patrick LeBlanc | Senior Technical Specialist, Microsoft
3
Module Overview Introduction To DAX Syntax
Writing DAX Queries Outside SSMS Using DAX Queries In Practical World
4
Introduction To DAX Syntax
5
Querying With DAX Usage Syntax / Functions EVALUATE SUMMARIZE TopN
Many others to look into, e.g. ADDCOLUMN GENERATEALL CALCULATETABLE Tools to use DAX Editor DAX Studio When this would be useful Actions SSRS Report
6
DAX in SSMS: Evaluate DAX in DAX Editor: Summarize
7
EVALUATE [DEFINE {MEASURE <tableName>[<name>] = <expression>} EVALUATE <table> [ORDER BY {<expression> [{ASC | DESC}]}[, …] [START AT {<value>|<parameter>} [, …]]] Retrieve data from table expression. T-SQL Equivalent SELECT * FROM <table> Note Formatting configured in Tabular Model is lost
8
EVALUATE is similar to EVALUATE 'InternetSales'
SELECT * FROM [dbo].[FactInternetSales] EVALUATE 'InternetSales'
9
EVALUATE
10
SUMMARIZE SUMMARIZE(<table>, <groupBy_columnName>[, <groupBy_columnName>]…[, <name>, <expression>]…) Returns requested aggregated values over a set of groups T-SQL Equivalent SELECT <columns>, <aggregated columns> FROM <table> GROUP BY <columns> Type Statistical Function
11
SUMMARIZE is similar to …
EVALUATE SUMMARIZE ( 'InternetSales', 'Product'[Product Name], "Sales", SUM ( 'InternetSales'[Sales Amount] ), "Revenue", 'InternetSales'[Revenue] )
12
SUMMARIZE SELECT p.[EnglishProductName],
SUM(f.[SalesAmount]) AS Sales, SUM(f.[SalesAmount] - f.[ProductStandardCost] - f.[Freight] - f.[TaxAmt]) AS Revenue FROM [dbo].[FactInternetSales] f INNER JOIN [dbo].[DimProduct] p ON p.[ProductKey] = f.[ProductKey] GROUP BY p.[EnglishProductName];
13
SUMMARIZE
15
TopN TOPN(<n_value>, <table>, <orderBy_expression>, [<order>[, <orderBy_expression>, [<order>]]…]) Returns a table with the Cartesian product between each row in table1 and the table that results from evaluating table2 in the context of the current row from table1. T-SQL Equivalent SELECT <columns> FROM <table1> LEFT OUTER JOIN <table2> Type Filter Function
16
TopN EVALUATE FILTER ( GENERATE ( VALUES ( 'Date'[Calendar Year] ), ADDCOLUMNS ( TOPN ( 10, VALUES ( 'Product'[Product Name] ), 'InternetSales'[Sum of Sales], 0 ), "Sales", 'InternetSales'[Sum of Sales] ) ), 'InternetSales'[Sum of Sales] > 0 ) ORDER BY 'Date'[Calendar Year], "Sales" DESC
17
TopN – SQL Equivalent SELECT DISTINCT d.[CalendarYear],
s.[EnglishProductName], s.[Sales] FROM [dbo].[DimDate] d OUTER APPLY (SELECT TOP 10 p.[EnglishProductName], SUM(sx.[SalesAmount]) Sales FROM [dbo].[FactInternetSales] sx INNER JOIN [dbo].[DimDate] dx ON dx.[DateKey] = sx.[OrderDateKey] INNER JOIN [dbo].[DimProduct] p ON p.[ProductKey] = sx.[ProductKey] WHERE d.[CalendarYear] = dx.[CalendarYear] GROUP BY dx.[CalendarYear], p.[EnglishProductName] ORDER BY SUM(sx.[SalesAmount]) DESC ) s WHERE s.[Sales] > 0 d.[CalendarYear] ASC, s.[Sales] DESC
18
Writing DAX Queries Outside SSMS
19
DAX in DAX Studio: TopN
20
Tools To Use Add-In To Excel Add-In To VS 2010, 2012 DAX Editor
21
Using DAX Queries In Practical World
22
Creating custom DAX query for Action
23
DAX in Reporting Tools Create a Report Project
Change Command Type to DMX to write a DAX query Can also write MDX query as per normal SSAS
24
Alternative for SSRS If using In-Memory model, can use MDX on SSRS
25
Querying with DAX Session Takeaways Ability to write simple DAX Query
Know what tools to use to write DAX Query Using DAX Queries to inspect data in DAX Studio Embedding DAX Queries into Action Using DAX Query in SSRS
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.