
Studying the right way to use Energy BI is pretty simple, and if you happen to’re fortunate, the built-in options will present every thing you have to produce skilled dashboards for finish customers. Nonetheless, you’ll get extra out of this system if you happen to be taught Knowledge Evaluation Expressions. DAX is a group of features, operators and constants that you should utilize in expressions. It’s highly effective, but simple to be taught.
SEE: Hiring kit: Microsoft Power BI developer (TechRepublic Premium)
On this tutorial, you’ll be taught conceptual fundamentals and syntax guidelines for writing DAX expressions. We’ll additionally work by means of a easy instance. Should you’re following alongside, I’m utilizing Power BI Desktop on a Home windows 10 64-bit system.
You possibly can download the Microsoft Power BI demo file for this tutorial.
Soar to:
DAX phrases and ideas to know for Energy BI customers
As a Energy BI designer, you’ll need finish customers to get all of the insights they want from what you create. Sometimes, which means utilizing DAX, a set of features that consider knowledge to return significant data.
Most Energy BI designers are acquainted with writing expressions, and this skillset is particularly useful when studying DAX. Should you’re acquainted with Microsoft Excel features, you’re in luck, as a result of DAX and Excel features are comparable.
SEE: The Complete Microsoft Power BI Super Bundle (TechRepublic Academy)
Even when you have no expertise with expressions, you’ll be able to nonetheless be taught to make use of DAX. Step one is to know the right way to “communicate” DAX. That requires studying a set of primary grammatical guidelines, or syntax.
In English, you would possibly say: “I wish to sum the entire gross sales values for the yr 2021.” Energy BI can’t interpret that request. To make DAX be just right for you, faux that you simply’re studying a overseas language; in a way, that’s precisely what you’re doing, simply with a language of features, arguments and Energy BI context.
Capabilities
Capabilities are predefined directions for evaluating values that you simply provide. There are a number of classes: Date and Time, Time Intelligence, Data, Logical, Mathematical, Statistical, Textual content, Father or mother/Little one and extra.
Though most features return values, you can even return a desk. Capabilities all the time reference a desk or column, however you’ll be able to apply filters to consult with particular rows.
Arguments
Arguments assist you to go particular values to the operate for analysis. Arguments may be one other operate, an expression, a column reference, a set of values or textual content, logical values similar to TRUE and FALSE, and constants, giving context to the request.
Context
Earlier than we are able to transfer on to examples, we have to focus on context, which lets you categorical whether or not you’re coping with rows or filtered outcomes, as follows:
- Row context refers back to the present row, often applied by making use of filters. You’ll often use row context in measures.
- Filter context refers to filters utilized by a calculation. It’s a extra complicated dialogue.
Now you’re able to put a few of this newfound data to work by writing a DAX expression within the type of a measure.
Easy methods to write a DAX expression
Energy BI offers a variety of implicit measures, that are predefined calculations in DAX. You’ll all the time wish to examine what’s out there earlier than writing your individual to save lots of your self effort and time. When nothing’s out there, you’ll want to put in writing a mannequin or express measure.
Why are we beginning you out with a measure? As a result of it’s the best option to get began and, most definitely, it’s the best way you’ll clear up most customized calculation wants.
Utilizing the straightforward dataset proven in Determine A, let’s write a measure that returns a year-to-date worth for every file. This straightforward .pbix file makes use of the Date desk within the Fields pane because the Date desk.
Determine A

To start out, choose the Gross sales desk within the Fields pane after which click on New Measure on the contextual Desk Instruments tab within the Calculations group. Energy BI will enter Measure = within the ensuing components bar. Substitute it with the next DAX expression, as proven in Determine B:
Quantity YTD =
TOTALYTD(SUM('Gross sales'[Amount]), 'Date'[Date])
Determine B

Energy BI provides a measure named Measure to the Gross sales desk however doesn’t commit it simply but. Let’s take a look at this DAX expression by its particular person parts:
- Quantity YTD is the identify of the measure. When you commit the measure, Energy BI will replace the identify Measure within the Fields pane to Quantity YTD.
- TOTALYTD is a DAX operate that calculates the year-to-date complete for every row — there’s that row context we talked about above.
- SUM is one other DAX operate that returns the whole for the required values.
Syntax for correct DAX calculations
Now, let’s take a look at the syntax so you recognize what’s anticipated for DAX to interpret and calculate the outcomes you want.
The TOTALYTD operate makes use of the next syntax:
TOTALYTD(<expression>,<dates>[,<filter>][,<year_end_date>])
As talked about, TOTALYTD is a DAX operate that evaluates year-to-date values of <expression> inside the present (row) context. Now, let’s take a look at the arguments:
- TOTALYTD is the operate’s identify.
- expression is any expression that returns a scalar worth or single worth.
- dates is a column that comprises date values which might be used to find out the yr within the present row.
- filter is an non-obligatory argument that identifies a filter to the present context.
- year_end_date is an non-obligatory string with a date that defines the year-end date. The default is December 31, which implies you received’t must specify a date until you’re coping with a fiscal yr that doesn’t finish on December 31 of the present yr.
Now, let’s take a look at the DAX Sum operate, which sums the values in a column utilizing the syntax
SUM(<column>)
The one argument, column, identifies the column to complete.
Now, let’s check out another necessities:
- DAX requires that you simply wrap arguments in parentheses.
- DAX requires that you simply denote a desk with the one citation character.
- DAX requires that you simply denote a column with straight brackets.
- DAX requires that you simply separate arguments with a comma.
Decoding your DAX expression in English
With all of this new data in thoughts, are you able to categorical
Quantity YTD =
TOTALYTD(SUM('Gross sales'[Amount]), 'Date'[Date])
in English?
In English, this DAX expression says: “Return the sum of the Quantity column within the Gross sales desk, utilizing the date values within the Date desk’s Date column to find out the yr.” Briefly, you’ve written an expression, utilizing two DAX features, that returns a operating complete by the yr.
Easy methods to commit the DAX expression as a measure
Now, you’re able to commit the expression as a measure you could add to a visualization. To take action, click on the checkmark to the left of the components bar. Doing so will replace the identify Measure within the Fields pane checklist to Quantity YTD, as proven in Determine C. Should you get an error, overview the expression and proper any typos.
Determine C

Earlier, I discussed that Date is a date desk. Should you’re not acquainted with date tables, don’t fear. Energy BI does a superb job of dealing with dates internally. Nonetheless, if you happen to’d prefer to be taught extra, learn the next articles:
To be taught extra about Energy BI measures, you’ll be able to learn these articles:
Now, let’s see how the DAX expression written as a measure works.
Easy methods to use the DAX expression as a measure in Energy BI
Including the measure doesn’t do a lot of something. Energy BI updates the identify of the measure within the Fields pane, however you must manually add it to a visualization to see the way it works. Let’s do this now, utilizing the straightforward Desk visualization proven within the figures.
To take action, click on the Desk visualization to pick it. Then, examine the Quantity YTD measure. Doing so provides it to the visualization, as you’ll be able to see in Determine D.
Determine D

We all know that the SUM operate totals the values within the Sum of Quantity column. That’s the identify Energy BI offers the Quantity column when it’s utilized in a visualization as a result of it’s a column that can be utilized in mathematical evaluations. You possibly can change it within the visualization if you happen to’d like, however the values you’re seeing are literal values from the Quantity column for now. There’s no summing happening in that column.
The TOTALYTD’s first argument is the SUM operate that’s summing the Quantity column within the Gross sales desk. The second argument tells Energy BI to start out a brand new complete when the yr in that column modifications. Discover what occurs between the 2 dates, 12/15/2021 and a pair of/17/2022. The latter date is in a brand new yr, so the whole begins over. That’s an inside instruction, so that you don’t have to put in writing any code to make it occur.
I’ve a shock for you, although. You don’t have to put in writing your individual year-to-date expression, as a result of Energy BI has a fast measure that does the identical factor. All you must do is establish the arguments: The tables and columns.
Continued studying about DAX expressions
One of many best methods to learn to use DAX is to discover fast measures. Merely discover the interface (Desk Instruments tab) and enter a number of. Once you see a operate or syntax you don’t perceive, you should utilize a search engine to be taught extra.
SEE: Quick glossary: Business intelligence and analytics (TechRepublic Premium)
Generally, there’s no different option to get the outcomes you want with out implementing DAX. Now that you recognize a bit about DAX, its syntax and some of its features, you’re prepared to start out writing expressions by yourself.
Learn subsequent: Best business intelligence tools (TechRepublic)