This covers material from the following Microsoft Learn modules:
Key ideas:
Model view:
A date table acts as a common center for your tables. It greatly simplifies time-based reports.
Option 1: specify start/end times
Dates = CALENDAR(DATE(2011, 5, 31), DATE(2022, 12, 31))
Option 2: let DAX figure out start/end times
Dates = CALENDARAUTO()
Once it is created, add columns for year, month, etc…
Year = YEAR(Dates[Date])
WeekNum = WEEKNUM(Dates[Date])
DayoftheWeek = FORMAT(Dates[Date], "DDDD")
You probably also want to specify things like holidays, as well as fiscal years.
If your fiscal year is from July to June, then you would use the following code.
FiscalYear = IF(month >= 7, year+1, year)
You should then mark the table as your official date table. Go to report view, fields, right-click the table, and select Mark as date table.
Now, go to the model and set the relationships. Join the new table (using date as a many to one) with all of your existing date values.
Help link: Calculated columns versus measures
A calculated column in PowerBI is different than a measure (note, we are not talking about PowerQuery!). A column is created, and exists for every row. This creates data which is then stored in PowerBI.
A measure is an aggregated value. These will always have a function used to collapse rows.
Both are written in DAX. You will generally go to the Table view to create a calculated column.
We regularly use an implicit measure, where we drag a field over and pick an aggregation function. However, there are time when we will deliberately write a explicit measure. This helps us to better control access to our data. By hard-coding in a SUM or COUNT, we make sure that people using our data later use the proper field.
Dates are the most common hierarchies, but we may want to define our own.
Process:
Now you can drill down in a visual.
This section has a brief discussion of the PATH
function, but that will not be covered in this course.
We will often want to use the same table in multiple ways. This is especially true to avoid having cycles in our relationships.
You can accomplish this by duplicating a table, and then join it back to your fact table.
Understand the different relationships:
Cross-filtering:
PowerBI has to understand how to go from one row in table A to another row in Table B. Typically, if you setup the joins correctly, this will work.
However, you sometimes need to look at the cross-filter direction. Avoid using cross-filter or bi-directional cross-filtering for many-to-many relationships. This can lead to significant data problems. PowerBI needs to have a single way of linking data.
Add a new column by going to the data view, clicking new column.
Here are some functions you should know:
Note that a new calculated column can only refer to fields in the
same table. To get out of the table, you can use other functions like
RELATED
. But, those are out of scope for this class.
A new measure is created with an aggregation DAX function.
Revenue = SUM(Sales[Sales Amount])
Add by going to data view, and clicking the add measure button. Be sure to set formatting after you create it.
Measure functions:
A quick measure can be used to quickly add a measure. Use the Quick Measure button under Table tools.