DAX and Power BI Training - 005 DAX Level 4

41
DAX Level 4

Transcript of DAX and Power BI Training - 005 DAX Level 4

Page 1: DAX and Power BI Training - 005 DAX Level 4

DAX Level 4

Page 2: DAX and Power BI Training - 005 DAX Level 4
Page 3: DAX and Power BI Training - 005 DAX Level 4

YTD

March

Page 4: DAX and Power BI Training - 005 DAX Level 4

YTD

March

Page 5: DAX and Power BI Training - 005 DAX Level 4

YTD

March

Page 6: DAX and Power BI Training - 005 DAX Level 4

CALCULATE() with ALL() and FILTER()

Page 7: DAX and Power BI Training - 005 DAX Level 4

2 Types of Filters:

Simple Filters & Advanced Filters

CALCULATE([measure], <filter1>, <filter2>, … <filterN>)

Page 8: DAX and Power BI Training - 005 DAX Level 4

2 Types of Filters:

Simple Filters & Advanced Filters

CALCULATE([measure], <filter1>, <filter2>, … <filterN>)

Page 9: DAX and Power BI Training - 005 DAX Level 4

ALL()

Page 10: DAX and Power BI Training - 005 DAX Level 4

ALL('table' or 'table'[column])

Page 11: DAX and Power BI Training - 005 DAX Level 4

#1 - Pick a cell in the pivot

Page 12: DAX and Power BI Training - 005 DAX Level 4

#1 - Pick a cell in the pivot

Page 13: DAX and Power BI Training - 005 DAX Level 4

#2 – Got DAX Filters?

Sales All Customers = CALCULATE([Sales],ALL('Customers'))

Page 14: DAX and Power BI Training - 005 DAX Level 4
Page 15: DAX and Power BI Training - 005 DAX Level 4

Sales All Customers = CALCULATE([Sales],ALL('Customers'))

Page 16: DAX and Power BI Training - 005 DAX Level 4

Sales All Customers = CALCULATE([Sales],ALL('Customers'))

Page 17: DAX and Power BI Training - 005 DAX Level 4

Sales All Customers = CALCULATE([Sales],ALL('Customers'))

Page 18: DAX and Power BI Training - 005 DAX Level 4

#3 - Picture filters reducing data in the model

Page 19: DAX and Power BI Training - 005 DAX Level 4

#4 - After filtering, apply math

Page 20: DAX and Power BI Training - 005 DAX Level 4

#4 - After filtering, apply math

Page 21: DAX and Power BI Training - 005 DAX Level 4

#4 - After filtering, apply math

Page 22: DAX and Power BI Training - 005 DAX Level 4

ALL()Qty % of Vendors

Page 23: DAX and Power BI Training - 005 DAX Level 4

FILTER()

Page 24: DAX and Power BI Training - 005 DAX Level 4

FILTER('table',<any filter>)

Page 25: DAX and Power BI Training - 005 DAX Level 4

FILTER()Non-Diversified Suppliers

Page 26: DAX and Power BI Training - 005 DAX Level 4

ALL() and FILTER()

Page 27: DAX and Power BI Training - 005 DAX Level 4

ALL() and FILTER()On Contract YTDOn Contract LYTD

Page 28: DAX and Power BI Training - 005 DAX Level 4

DAX Formatterhttp://www.daxformatter.com/

Page 29: DAX and Power BI Training - 005 DAX Level 4

Tip - DAX Step through formula

Page 30: DAX and Power BI Training - 005 DAX Level 4

Sales YTD :=CALCULATE (

[Sales],FILTER (

ALL ( 'Calendar' ),AND (

Calendar[Year] = MAX ( Calendar[Year] ),Calendar[Date] <= MAX ( Calendar[Date] )

))

)

Page 31: DAX and Power BI Training - 005 DAX Level 4

Sales YTD :=CALCULATE (

[Sales],FILTER (

,AND (

Calendar[Year] = MAX ( Calendar[Year] ),Calendar[Date] <= MAX ( Calendar[Date] )

))

)

Date Year

1/1/2014 2014

1/2/2014 2014

… …

12/30/2018 2018

12/31/2018 2018

Page 32: DAX and Power BI Training - 005 DAX Level 4

Sales YTD :=CALCULATE (

[Sales],FILTER (

,AND (

Calendar[Year] = 2016,Calendar[Date] <= “2/29/2016”

))

)

Date Year

1/1/2014 2014

1/2/2014 2014

… …

12/30/2018 2018

12/31/2018 2018

Page 33: DAX and Power BI Training - 005 DAX Level 4

Sales YTD :=CALCULATE (

[Sales],FILTER (

,AND (

True,True

))

)

Date Year

1/1/2014 2014

1/2/2014 2014

… …

12/30/2018 2018

12/31/2018 2018

Page 34: DAX and Power BI Training - 005 DAX Level 4

Sales YTD :=CALCULATE (

[Sales],FILTER (

,True)

))

Date Year

1/1/2014 2014

1/2/2014 2014

… …

12/30/2018 2018

12/31/2018 2018

Page 35: DAX and Power BI Training - 005 DAX Level 4

Sales YTD :=CALCULATE (

[Sales],

)

Date Year

1/1/2016 2016

1/2/2016 2016

… …

2/28/2016 2016

2/29/2016 2016

Page 36: DAX and Power BI Training - 005 DAX Level 4

Sales YTD :=CALCULATE (

[Sales],

)

Date Year

1/1/2016 2016

1/2/2016 2016

… …

2/28/2016 2016

2/29/2016 2016

Filter the Sales table through relationship in the model.

Brand Customer Item Division Requested Ship Date Gross Line Amount

Brand 8 Customer 2 Item No 350 Division 2 1/1/2014 5.49

Brand 8 Customer 2 Item No 350 Division 2 1/2/2014 7.37

… … … … … …

Brand 8 Customer 2 Item No 350 Division 2 4/23/2016 8.45

Brand 8 Customer 2 Item No 350 Division 2 4/24/2016 3.45

Page 37: DAX and Power BI Training - 005 DAX Level 4

Sales YTD :=$9,779,779

Brand Customer Item Division Requested Ship Date Gross Line Amount

Brand 8 Customer 2 Item No 350 Division 2 1/1/2016 3.56

Brand 8 Customer 2 Item No 350 Division 2 1/2/2016 5.07

… … … … … …

Brand 8 Customer 2 Item No 350 Division 2 2/28/2016 4.22

Brand 8 Customer 2 Item No 350 Division 2 2/29/2016 5.8

Do the math and return the value to the cell in the pivot table.

Page 38: DAX and Power BI Training - 005 DAX Level 4

Exercise• ALL()

• Qty % of Vendors

• FILTER()• Non-Diversified Suppliers

• ALL() and FILTER()• On Contract YTD

• On Contract LYTD

Page 39: DAX and Power BI Training - 005 DAX Level 4

DAX Books

Page 40: DAX and Power BI Training - 005 DAX Level 4

Homework• Finish creating metrics

• Explore a real world dataset with Power Query

• Practice your transformation skills by turning the data into something useful

• Share your Power Query experience with Steve

Page 41: DAX and Power BI Training - 005 DAX Level 4

Next Week• Beginner Power Pivot

• Logical Functions IF() and SWITCH()

• Time Intelligence Functions

• Budget vs Actual or Benchmark vs Actual