PBI Desktop Fundamentals Training Session 2
PBI Desktop Fundamentals Training Session 2
1
TRAINING STRUCTURE
Calculated columns understand row context; they’re DO NOT use calculated columns for
great for defining properties based on information in aggregation formulas, or to
each row, but generally useless for aggregation (SUM, calculate fields for the “Values”
COUNT, etc) area of a visualization (use
measures instead)
CALCULATED COLUMNS
(EXAMPLES)
In this case we’ve added a calculated column named
“Parent”, which equals “Yes” if the [TotalChildren] field
is greater than 0, and “No” otherwise (just like Excel!)
• Since calculated columns understand row context, a
new value is calculated in each row based on the
value in the [TotalChildren] column
• This is a valid use of calculated columns; it creates a
new row “property” that we can now use to filter or
segment any related data within the model
Implicit measures are created when you drag raw numerical fields
(like “OrderQuantity”) into the values pane of a visual and manually
select the aggregation mode (Sum, Average, Min/Max, etc)
TIP:
Implicit measures are only accessible within the specific visualization
in which it was created, and cannot be referenced elsewhere
Explicit measures can be used anywhere in the report, and
referenced
within other DAX calculations to create “measure trees”
Example of an implicit measure
Practice: IMPLICIT VS. EXPLICIT MEASURES
Try two ways to create an
Explicit Measure using DAX
Remember that measures are evaluated based on filter context, which means that they
recalculate whenever the fields or filters around them change
For this particular value in the matrix, the Total Orders measure is calculated based on the
following filter context: Products[ProductName] = “Touring Tire Tube”
This allows the measure to return the total order quantity for each product specifically (or
whatever the row and column labels dictate – years, countries, product categories,
customer names…)
This Total is not calculated by summing the values above; it evaluates as its own measure,
with no filter context (since we aren’t calculating orders for a specific product)
TIP:
Each measure value in a report is like an island, and calculates according to it’s own filter
context (even Totals and Grand Totals)
FILTER CONTEXT
MEASURE: Total Revenue
(EXAMPLES)
MEASURE: Total Orders MEASURE: Total Orders
FILTER CONTEXT: FILTER CONTEXT:
FILTER CONTEXT:
Calendar[Year] = 2016 or 2017 Calendar[Year] = 2016 or 2017
Customers[Gender] = F (Female) Calendar[Year] = 2016 or 2017
Customers[Full Name] = Mr. Larry Munoz
Customers[Occupation] = Clerical
This is a page-level
filter, which impact
ALL visuals on the
report page
Product Table
Accessories
Product[CategoryName] = “Accessories”
= 1,115
Count of rows in the AW_Returns_Data
Product Table table, filtered down to only rows where
11 the product category is “Accessories”
Accessories
AW_Returns_Data
*
* Accessories
AW_Sales_Data
Accessories
Practice: Filter Contexts
Add a page level filter
context – Year 2016 2017,
observe the different
changes it applies to every
visuals
Click on Categories in a
visual to see how it filters
the other visual accordingly
COMMON DAX FUNCTIONS
DAX SYNTAX
MEASURE NAME
Referenced Referenced
• Note: Measures are always surrounded
in brackets (i.e. [Total Quantity]) when TABLE NAME COLUMN NAME
referenced in formulas, so spaces are OK
& Concatenates two values to produce one text string [City] & “ “ & [State]
&& Create an AND condition between two logical expressions ([State]=“MA”) && ([Quantity]>10)
|| (double pipe) Create an OR condition between two logical expressions ([State]=“MA”) || ([State]=“CT”)
IN Creates a logical OR condition based on a given list (using curly brackets) ‘Store Lookup’[State] IN { “MA”, “CT”, “NY” }
COMMON FUNCTION CATEGORIES
Common Examples: Common Examples: Common Examples: Common Examples: Common Examples:
• SUM • IF • CONCATENATE • CALCULATE • DATEDIFF
• AVERAGE • IFERROR • FORMAT • FILTER • YEARFRAC
• MAX/MIN • AND • LEFT/MID/RIGHT • ALL • YEAR/MONTH/DAY
• DIVIDE • OR • UPPER/LOWER • ALLEXCEPT • HOUR/MINUTE/SECOND
• COUNT/COUNTA • NOT • PROPER • RELATED • TODAY/NOW
• COUNTROWS • SWITCH • LEN • RELATEDTABLE • WEEKDAY/WEEKNUM
• DISTINCTCOUNT • TRUE • SEARCH/FIND • DISTINCT
• FALSE • REPLACE • VALUES Time Intelligence Functions:
Iterator Functions: • REPT • EARLIER/EARLIEST • DATESYTD
• SUBSTITUTE • HASONEVALUE • DATESQTD
• SUMX
• TRIM • HASONEFILTER • DATESMTD
• AVERAGEX
• UNICHAR • ISFILTERED • DATEADD
• MAXX/MINX
• USERELATIONSHIP • DATESINPERIOD
• RANKX
• COUNTX
BASIC DATE & TIME FUNCTIONS
YEAR() YEAR(Date)
HOUR/MINUTE/ Returns the hour (0-23), minute (0-59), or
second (0-59) of a given datetime value =HOUR/MINUTE/SECOND(Datetime)
SECOND()
)
CONCATENATE() Joins two text strings into one =CONCATENATE(Text1, Text2)
RELATED() Returns related values in each row of a table based on relationships with other tables
=RELATED(ColumnName) TIP:
RELATED works almost exactly like a VLOOKUP function – it uses
the relationship between tables (defined by primary and foreign
keys) to pull values from one table into a new column of another
The column that contains the
values you want to retrieve Since this function requires row context, it can only be used as a
calculated column or as part of an iterator function that cycles
Examples: through all rows in a table (FILTER, SUMX, MAXX, etc)
• Product_Lookup[ProductName] Avoid using RELATED to create redundant calculated columns
• Territory_Lookup[Country] unless you absolutely need them, since those extra columns
increase file size; instead, use RELATED within a measure like
FILTER or SUMX
Practice: Related()
Use Related() function to
bring new column data from
another table to Sales table
(Product Price)
Name of an existing measure, or a DAX List of simple Boolean (True/False) filter expressions
formula for a valid measure (note: these require simple, fixed values; you cannot
Examples:
create filters based on measures)
• [Total Orders] Examples:
• SUM(Returns_Data[ReturnQuantity]) • Territory_Lookup[Country] = “USA”
• Calendar[Year] > 1998
TIP:
CALCULATE works just like SUMIF or COUNTIF in Excel, except it can evaluate measures based on ANY
sort of calculation (not just a sum, count…)
CALCULATE
(EXAMPLE)
TIP:
Instead of adding filter context, ALL removes it. This is often used when you need unfiltered values that
won’t react to changes in filter context (i.e. % of Total, where the denominator needs to remain fixed)
Practice: All()
Use ALL() function to create
ALL orders, use that to
calculate % of ALL orders;
and Avg Retail Price for
Sales and Product tables
FILTE
R
FILTER() Returns a table that represents a subset of another table or expression
=SUMX(Table, Expression)
Aggregation to apply Table in which the Expression to be evaluated for
to calculated rows expression will be evaluated each row of the given table
Examples: Examples: Examples:
• SUMX • Sales • [Total Orders]
• COUNTX • FILTER(Sales, • Sales[RetailPrice] * Sales[Quantity]
• AVERAGEX RELATED(Products[Category])=“Clothing”)
• RANKX
• MAXX/MINX
TIP:
Imagine the function adding a temporary new column to the table, calculating the value in each row
(based on the expression) and then applying the aggregation to that new column (like SUMPRODUCT)
Practice: …X() functions
Try calculating Total revenue
with Sum and Sumx to
understand the difference
Time Intelligence functions allow you to easily calculate common time comparisons:
TIP:
To calculate a moving average, use the running total calculation above and divide by the number of intervals
Practice: Date Time functions
Create a Matrix visual
Write measures for even the simplest calculations (i.e. Sum of Sales)
Once you create a measure it can be used anywhere in the report and as an input to other, more complex
calculations (no implicit measures!)
Fields/Format/Analytics Pane
(Visual-specific configuration &
formatting tools)
Report Pages (Similar to Excel tabs; each is a blank reporting canvas) Filters Pane (Visual-Level, Page-Level, and Report-Level Filters)
INSERTING OBJECTS & BASIC CHARTS
Basic Options
Top N Options Advanced (Values)
Advanced (Text)
Practice: Filtering Options
Create similar Matrix with
CategoryName in the Axis of the
visual instead
Note that
Trend line
requires X axis
of the Line
chart visual to
be Continuous
data to apply
EDITING REPORT INTERACTIONS
Report interactions allow you to determine how filters applied to one visual impact the others
For example, by selecting the Timeline visual and enabling “Edit interactions” from the Format tab, we can manually determine which visuals should
“react” when the date range changes
In this case the Product matrix, Country slicer and Map will filter in response to timeline changes ( ), but the MTD, QTD, and YTD Profit cards
will not ( )
IMPORTING CUSTOM VISUALS