dax best practices - power bi user group

17
PowerBIWorldTour.com #PBIWorldTour DAX Best Practices Daniil Maslyuk

Upload: others

Post on 13-Jan-2022

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: DAX Best Practices - Power BI User Group

PowerBIWorldTour.com #PBIWorldTour

DAX Best PracticesDaniil Maslyuk

Page 2: DAX Best Practices - Power BI User Group

PowerBIWorldTour.com #PBIWorldTour

DAX Best Practices

This is a very technical session!

Today, we will be

• Reviewing examples of DAX code from the real world in demos

• Spotting issues

• Formulating best practices

Page 3: DAX Best Practices - Power BI User Group

PowerBIWorldTour.com #PBIWorldTour

Session Agenda

• Introduction

• Demo 1: readability

• Demo 2: constructs necessity

• Demo 3: repetitions

• Demo 4: repetitions II

• Demo 5: filtering

• Demo 6: references

Page 4: DAX Best Practices - Power BI User Group

PowerBIWorldTour.com #PBIWorldTour

Daniil Maslyuk• Consultant at Analytics8

• Author of the official Power BI Exam Ref (70-778) book

• Technical editor of The Definitive Guide to DAX, 2nd edition

• Blog: xxlbi.com

• Twitter: @DMaslyuk

Page 5: DAX Best Practices - Power BI User Group

PowerBIWorldTour.com #PBIWorldTour

Demo 1: readability

Page 6: DAX Best Practices - Power BI User Group

PowerBIWorldTour.com #PBIWorldTour

Best practice: format your code!

• Use DAX Formatter• www.daxformatter.com

• Also part of DAX Studio and Tabular Editor

• Use DAX formula bar keyboard shortcuts• https://xxlbi.com/blog/dax-formula-bar-keyboard-shortcuts-in-power-bi-

desktop/

Page 7: DAX Best Practices - Power BI User Group

PowerBIWorldTour.com #PBIWorldTour

Demo 2: constructs necessity

Page 8: DAX Best Practices - Power BI User Group

PowerBIWorldTour.com #PBIWorldTour

Best practice: learn theory!

• DAX is not SQL

• DAX is not MDX

• DAX is not Excel formula language

Page 9: DAX Best Practices - Power BI User Group

PowerBIWorldTour.com #PBIWorldTour

Demo 3: repetitions

Page 10: DAX Best Practices - Power BI User Group

PowerBIWorldTour.com #PBIWorldTour

Best practice: reuse measures!

• Split your calculations in smaller blocks

• Reuse measures instead of writing the same code

• DRY (don’t repeat yourself) still applies

Page 11: DAX Best Practices - Power BI User Group

PowerBIWorldTour.com #PBIWorldTour

Demo 4: repetitions II

Page 12: DAX Best Practices - Power BI User Group

PowerBIWorldTour.com #PBIWorldTour

Best practice: use variables!

• Variables can be used to document your code

• Variables can help you avoid repetition

• Be aware that variables are actually constants

Page 13: DAX Best Practices - Power BI User Group

PowerBIWorldTour.com #PBIWorldTour

Demo 5: filtering

Page 14: DAX Best Practices - Power BI User Group

PowerBIWorldTour.com #PBIWorldTour

Best practice: filter columns, not tables!

• Do not filter whole tables

• Filter columns

• Filter selected columns

Page 15: DAX Best Practices - Power BI User Group

PowerBIWorldTour.com #PBIWorldTour

Demo 6: references

Page 16: DAX Best Practices - Power BI User Group

PowerBIWorldTour.com #PBIWorldTour

Best practice: follow naming conventions!

• Column reference: Table[Column]

• Measure reference: [Measure]

• User-friendly names are the best

• There is no problem with spaces in names

Page 17: DAX Best Practices - Power BI User Group

Don’t forget to join your local PUG to enjoy year-round networking and learning.