Presentation is loading. Please wait.

Presentation is loading. Please wait.

DAX: Functions and Context That’s What It’s All About!

Similar presentations


Presentation on theme: "DAX: Functions and Context That’s What It’s All About!"— Presentation transcript:

1 DAX: Functions and Context That’s What It’s All About!
Brian Larson DAX: Functions and Context That’s What It’s All About!

2 Thank you Sponsors! Platinum Sponsor: Gold Sponsors:
Visit the Sponsor Booths Lots of Great Raffle Prizes! Get your parking paid via Sponsor Bingo Thank you Sponsors! Platinum Sponsor: Gold Sponsors: Global Alliance Partners:

3 PASSMN – News/Info Thanks to all our sponsors of 2019!
We need Speakers & Sponsors for 2020 PASSMN Meetings! Sign up to present at one of the monthly meetings! Monthly Meetup: 3rd Tuesday of Each Month (except Oct) at Microsoft MTC in Edina (food usually provided) Signup on Meetup: Board Member Elections in November/December: Your chance to help out the MN SQL community!

4 November 3th Through November 8th
Join the brightest data professionals focused on the Microsoft Data Platform! November 3th Through November 8th Pre-Conference Sessions – Monday/Tuesday Conference – Wednesday through Friday

5 SQLSaturday #913 – After Party
Location: 4th Floor of Mall of America Time: 6:30PM – 10PM There will be drinks and appetizers as well as free game cards and bowling! Hang out with some new friends you’ve made.

6 Brian Larson 17 years experience with Microsoft Data Visualization Tools Contributed to the initial codebase of SQL Server Reporting Service Author on Business Intelligence and Data Visualization topics for McGraw-Hill Education

7 Agenda Context Creating Our Own Context Overriding External Context
Time Analytics DAX Variables

8 Locations for a DAX Expression
In a calculated column In a measure

9 Default Context in a Calculated Column
Default Context is the row

10 Aggregate in a Calculate Column
Context is the entire table . . .

11 Default Context in a Measure
. . . Context is the entire table

12 Demo in Power BI

13 Measures Respond to Filters and Slicers
Only Sales for Calendar 2018 Only Sales for Eddie Only Sales for Guiding Lights

14 Measures Respond to Filters and Slicers
Sales in Dollars = SUM('Orders'[Sales in US Dollars]) 2018 Guiding Lights Orders for Eddie 2018 Guiding Lights Orders By Product Type By Sales Person Sales in Dollars $3,557,857.80 Only 2018 . . . . . . All Orders . . . 2018 Orders 2018 Woodland Creatures Orders for Zeb 2018 Woodland Creatures Orders Slicers and Filters Sales in Dollars $6,308,134.20 Rows Columns Calculate Measure

15 Aggregate in a Calculated Column
Does not react to User Filters

16 Filter Condition in a Measure
Large Order Sales = CALCULATE([Sales in Dollars], Orders[Sales in US Dollars]>150) 2018 Guiding Lights Orders for Eddie 2018 Guiding Lights Orders > $150 By Product Type By Sales Person Large Order Sales {Blank} Only 2018 . . . . . . . . . All Orders . . . 2018 Orders 2018 Woodland Creatures Orders for Zeb > $150 2018 Woodland Creatures Orders Large Order Sales $4,851,848.40 Slicers and Filters Measure Filter Rows Columns Calculate Measure

17 Same Attribute in Slicer & Measure Filter
Guiding Lights Sales = CALCULATE([Sales in Dollars], 'Products'[Product Type]="Guiding Lights") 2018 Guiding Lights Orders for Eddie 2018 Guiding Lights Orders Guiding Lights 2018 Guiding Lights Sales for Eddie $3,557,857.80 X X By Product Type By Sales Person Only 2018 X . . . . . . . . . . . . All Orders 2018 Orders 2018 Guiding Lights Sales for Zeb $2,120,164.20 Guiding Lights 2018 Woodland Creatures Orders for Zeb 2018 Woodland Creatures Orders X Slicers and Filters X Measure Filter Rows Columns Calculate Measure

18 Multiple Attributes Filtered in Measure
Guiding Lights 2017 Sales = CALCULATE([Sales in Dollars], 'Products'[Product Type]="Guiding Lights", 'Time'[Year]=2017) All X X 2018 Guiding Lights Orders for Briggette Guiding Lights 2017 2017 Guiding Lights Sales for Briggette $1,383,984.00 2018 Guiding Lights Orders X By Product Type X By Sales Person All Only 2018 X X . . . 2018 Orders X . . . . . . . . . All Orders All X X Guiding Lights 2017 2017 Guiding Lights Sales for Zeb $2,115,498.00 2018 Woodland Creatures Orders for Zeb 2018 Woodland Creatures Orders X X Slicers and Filters Measure Filter Rows Columns Calculate Measure

19 Overriding a User Filter/Slicer with ALL()
Guiding Lights All Years Sales = CALCULATE([Sales in Dollars], 'Products'[Product Type]="Guiding Lights", ALL(‘Date')) All Guiding Lights Sales for all years for Briggette $4,109,305.20 X X 2018 Guiding Lights Orders for Briggette Guiding Lights All Years 2018 Guiding Lights Orders X By Product Type X By Sales Person All Only 2018 X . . . X . . . . . . . . . All Orders 2018 Orders All Guiding Lights Sales for all years for Zeb $6,323,343.60 X X Guiding Lights All Years 2018 Woodland Creatures Orders for Zeb 2018 Woodland Creatures Orders X Slicers And Filters X Measure Filter Rows Columns Calculate Measure

20 Overriding Filter/Slicer with ALLEXCEPT()
All Sales Selected Year = CALCULATE([Sales in Dollars], ALLEXCEPT('Orders', ‘Date'[Year])) 2018 Guiding Lights Orders for Andy 2018 Guiding Lights Orders All Except Year 2018 Sales $119,353,112.92 X X By Product Type By Sales Person Only 2018 X X X . . . . . . . . . . . . 2018 Orders All Except Year 2018 Sales $119,353,112.92 2018 Woodland Creatures Orders for Zeb 2018 Woodland Creatures Orders X X Slicers and Filters X Measure Filter Rows Columns Calculate Measure

21 RELATED() Function Orders Product
Unit Price = RELATED(Products[Retail Price]) Orders Product Product Unit Price 2 $22.05 5 $15.75 6 $14.70 4 $25.20 Product Code Product Retail Price 2 Boston, MS Harbor Lighthouse $22.05 3 Cape Hatteras, NC Lighthouse $18.90 4 Portland, ME Lighthouse $25.20 5 Split Rock, MN Lighthouse $15.75 6 Manitowoc, WI Lighthouse $14.70

22 LOOKUPVALUE() Function
Unit Price = LOOKUPVALUE(Products[Retail Price], [Product Code], [Product]) Orders Product X Product Unit Price 2 $22.05 5 $15.75 6 $14.70 4 $25.20 Product Code Product Retail Price 2 Boston, MS Harbor Lighthouse $22.05 3 Cape Hatteras, NC Lighthouse $18.90 4 Portland, ME Lighthouse $25.20 5 Split Rock, MN Lighthouse $15.75 6 Manitowoc, WI Lighthouse $14.70 Relationship created on the fly

23 SUMX() Iterative Function
Calcd Total Sales = SUMX('Orders’, 'Orders’[Sales in Units] * 'Orders’[Unit Price]) Date Of Product Sales in Unit Order Code Units Price 1/1/ $11.75 $705.00 $5,145.00 $8,501.76 $680.40 $4,838.40 $823.20 $3,175.20 1/1/ $36.75 1/1/ $29.52 1/2/ $18.90 1/2/ $50.40 1/3/ $14.70 1/3/ $29.40 $23, Calcd Total Sales

24 Using the FILTER() Function
Total Sales for Medium Priced Items = SUMX(FILTER('Orders’, 'Orders'[Unit Price] >= && 'Orders'[Unit Price] <= 30.00), 'Orders'[Unit Price] * 'Orders'[Sales in Units]) 2018 Guiding Lights Orders for Eddie 2018 Guiding Lights Orders Medium Priced Total Sales for Medium Priced Items $236,048.40 By Product Type By Sales Person Only 2018 . . . . . . . . . All Orders . . . 2018 Orders 2018 Woodland Creatures Orders for Zeb Medium Priced Total Sales for Medium Priced Items $657,643.20 2018 Woodland Creatures Orders Slicers and Filters Rows Columns Measure Filter Calculate Measure

25 Using the DATESYTD() Function
YTD Sales:=CALCULATE([Sales in Dollars], DATESYTD(‘Date'[Date])) 2018 Guiding Lights Orders for January 2018 Guiding Lights Orders Set of Dates YTD Guiding Lights January YTD Sales $895,452.60 By Product Type By Month Only 2018 . . . . . . . . . All Orders . . . 2018 Orders 2018 Woodland Creatures Orders for December Set of Dates YTD Woodland Creatures December 2018 YTD Sales $30,806,383.28 2018 Woodland Creatures Orders Slicers and Filters Rows Columns Measure Filter Calculate Measure

26 Using the DATESYTD() Function
YTD Sales:=CALCULATE([Sales in Dollars], DATESYTD('Time'[Date])) 2018 Guiding Lights Orders for January 2018 Guiding Lights Orders for January SUM(…) Sum all Sales in the Virtual Table DATESYTD(…) Filtered Rows Virtual Table New Virtual Table

27 Using the DATESYTD() Function
YTD Sales:=CALCULATE([Sales in Dollars], DATESYTD('Time'[Date])) 2018 Guiding Lights Orders for January - February 2018 Guiding Lights Orders for February SUM(…) Sum all Sales in the Virtual Table DATESYTD(…) Filtered Rows Virtual Table New Virtual Table

28 Using the DATESYTD() Function
YTD Sales:=CALCULATE([Sales in Dollars], DATESYTD('Time'[Date])) 2018 Guiding Lights Orders for January - March 2018 Guiding Lights Orders for March SUM(…) Sum all Sales in the Virtual Table DATESYTD(…) Filtered Rows Virtual Table New Virtual Table

29 Using the DATESBETWEEN() Function
Curr Qtr Sales:=CALCULATE([Sales in Dollars], DATESBETWEEN(‘Date'[Date], STARTOFQUARTER(‘Date'[Date]), ENDOFQUARTER(‘Date'[Date]))) 2018 Guiding Lights Orders for January 2018 Guiding Lights Orders Set of Dates Curr Qtr Guiding Lights Quarter Sales $2,348,602.20 By Product Type By Month Only 2018 . . . . . . . . . All Orders . . . 2018 Orders 2018 Woodland Creatures Orders for December Set of Dates Curr Qtr Woodland Creatures Quarter Sales $7,512,391.48 2018 Woodland Creatures Orders Slicers and Filters Rows Columns Measure Filter Calculate Measure

30 Using the DATESBETWEEN() Function
Curr Qtr Sales:=CALCULATE([Sales in Dollars], DATESBETWEEN(‘Date'[Date], STARTOFQUARTER(‘Date'[Date]), ENDOFQUARTER(‘Date'[Date]))) 2018 Guiding Lights Orders for Quarter 1 2018 Guiding Lights Orders for January SUM(…) Sum all Sales in the Virtual Table DATESBETWEEN(…) Filtered Rows Virtual Table New Virtual Table

31 Using the DATESBETWEEN() Function
Curr Qtr Sales:=CALCULATE([Sales in Dollars], DATESBETWEEN(‘Date'[Date], STARTOFQUARTER(‘Date'[Date]), ENDOFQUARTER(‘Date'[Date]))) 2018 Guiding Lights Orders for Quarter 2 2018 Guiding Lights Orders for April SUM(…) Sum all Sales in the Virtual Table DATESBETWEEN(…) Filtered Rows Virtual Table New Virtual Table

32 Using the PARALLELPERIOD() Function
Prev Qtr Sales:=CALCULATE([Sales in Dollars], PARALLELPERIOD(‘Date'[Date],-1, QUARTER)) 2018 Guiding Lights Orders for January 2018 Guiding Lights Orders Set of Dates Prev Qtr Guiding Lights Quarter Sales $2,631,375.60 By Product Type By Month Only 2018 . . . . . . . . . All Orders . . . 2018 Orders 2018 Woodland Creatures Orders for December Set of Dates Prev Qtr Woodland Creatures Quarter Sales $7,839,298.88 2018 Woodland Creatures Orders Slicers and Filters Rows Columns Measure Filter Calculate Measure

33 Using the PARALLELPERIOD() Function
Prev Qtr Sales:=CALCULATE([Sales in Dollars], PARALLELPERIOD(‘Date'[Date],-1, QUARTER)) 2018 Guiding Lights Orders for January 2017 Guiding Lights Orders for Quarter 4 SUM(…) Sum all Sales in the Virtual Table PARALLELPERIOD(…) Filtered Rows Virtual Table New Virtual Table

34 Using the PARALLELPERIOD() Function
Prev Qtr Sales:=CALCULATE([Sales in Dollars], PARALLELPERIOD(‘Date'[Date],-1, QUARTER)) 2018 Guiding Lights Orders for April 2018 Guiding Lights Orders for Quarter 1 SUM(…) Sum all Sales in the Virtual Table PARALLELPERIOD(…) Filtered Rows Virtual Table New Virtual Table

35 Using Variables in a Measure
Qtr Over Qtr Sales Growth:= VAR QtrOverQtrDiff = [Curr Qtr Sales] - [Prev Qtr Sales] return IF([Prev Qtr Sales] <> 0, DIVIDE(QtrOverQtrDiff, [Prev Qtr Sales]))

36 Table-valued Variables
Unit Sales not on Promo of Top 5 $ Sellers = VAR topProd = TOPN(5, 'Product', [Sales in Dollars]) RETURN CALCULATE(SUMX(topProd, [Sales in Units]), ISBLANK('Promotion'[Promotion Name])) Unit Sales on Promo of Top 5 $ Sellers = RETURN CALCULATE(SUMX(topProd, [Sales in Units]), NOT ISBLANK('Promotion'[Promotion Name]))

37 Returning Text from a Measure
Unit Sales not on Promo of Top 5 $ Sellers = VAR topProd = TOPN(5, 'Product', [Sales in Dollars]) RETURN CONCATENATEX(topProd, [Product], “, “)

38 Questions

39 Thank You @Brian_Larson /BrianLarsonSCS


Download ppt "DAX: Functions and Context That’s What It’s All About!"

Similar presentations


Ads by Google