Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Expert Data Modeling with Power BI

You're reading from   Expert Data Modeling with Power BI Get the best out of Power BI by building optimized data models for reporting and business needs

Arrow left icon
Product type Paperback
Published in Jun 2021
Publisher Packt
ISBN-13 9781800205697
Length 612 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Soheil Bakhshi Soheil Bakhshi
Author Profile Icon Soheil Bakhshi
Soheil Bakhshi
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Section 1: Data Modeling in Power BI
2. Chapter 1: Introduction to Data Modeling in Power BI FREE CHAPTER 3. Chapter 2: Data Analysis eXpressions and Data Modeling 4. Section 2: Data Preparation in Query Editor
5. Chapter 3: Data Preparation in Power Query Editor 6. Chapter 4: Getting Data from Various Sources 7. Chapter 5: Common Data Preparation Steps 8. Chapter 6: Star Schema Preparation in Power Query Editor 9. Chapter 7: Data Preparation Common Best Practices 10. Section 3: Data Modeling
11. Chapter 8: Data Modeling Components 12. Chapter 9: Star Schema and Data Modeling Common Best Practices 13. Section 4: Advanced Data Modeling
14. Chapter 10: Advanced Data Modeling Techniques 15. Chapter 11: Row-Level Security 16. Chapter 12: Extra Options and Features Available for Data Modeling 17. Other Books You May Enjoy

Understanding custom functions

In many cases, we may face a situation where we repeatedly need to calculate something. In such cases, it makes absolute sense to create a custom function that takes care of all the calculation logic needed. After defining a custom function, we can invoke this function many times. As stated in the Introduction to Power Query M formula language in Power BI section, under Function value, we can create a custom function by putting the list of parameters (if any) in parentheses, along with the output data type and the goes-to symbol =>, followed by a definition of the function.

The following example shows a straightforward form of a custom function that gets a date input and adds one day to it:

SimpleFunction = (DateValue as date) as date =>
Date.AddDays(DateValue, 1)

We can simply invoke the preceding function as follows:

SimpleFunction(#date(2020,1,1))

The result of invoking the function is 2/01/2020.

We can define a custom function...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime