Reader small image

You're reading from  Expert Data Modeling with Power BI - Second Edition

Product typeBook
Published inApr 2023
PublisherPackt
ISBN-139781803246246
Edition2nd Edition
Right arrow
Author (1)
Soheil Bakhshi
Soheil Bakhshi
author image
Soheil Bakhshi

Soheil Bakhshi is the founder of Data Vizioner and is a sought after BI consultant. Working in data and analytics for more than 20 years, Soheil's experience lies in Microsoft BI, Data Warehousing, and Power BI platform. He possesses MSCE, MCSA certifications and is a Microsoft MVP (Most Valuable Professional). He has a passion for sharing knowledge via his website and speaking at conferences and Power BI community events locally and globally. In following his desire for simplicity and efficiency, he is behind Power BI community tools and commercial products such as Power BI Exporter and Power BI Documenter.
Read more about Soheil Bakhshi

Right arrow

Understanding custom functions

In many cases, we are in a situation where we require repetitive transformation logic. In such cases, creating a custom function that takes care of all the calculation logic needed makes sense. After defining the custom function, we invoke it many times. As stated in the Introducing the Power Query M formula language in Power BI section, under Function value, we create a custom function by putting the parameters (if any) and their data type in parentheses, along with the output data type and the goes-to symbol =>, followed by the 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 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 as an inline...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Expert Data Modeling with Power BI - Second Edition
Published in: Apr 2023Publisher: PacktISBN-13: 9781803246246

Author (1)

author image
Soheil Bakhshi

Soheil Bakhshi is the founder of Data Vizioner and is a sought after BI consultant. Working in data and analytics for more than 20 years, Soheil's experience lies in Microsoft BI, Data Warehousing, and Power BI platform. He possesses MSCE, MCSA certifications and is a Microsoft MVP (Most Valuable Professional). He has a passion for sharing knowledge via his website and speaking at conferences and Power BI community events locally and globally. In following his desire for simplicity and efficiency, he is behind Power BI community tools and commercial products such as Power BI Exporter and Power BI Documenter.
Read more about Soheil Bakhshi