6. DAX Functions - Filter Functions
6. DAX Functions - Filter Functions
Trainings
CALCULATE
Syntax
CALCULATE (<expression>, <filter1>, <filter2>…)
Examples
EastCentralSales=
CALCULATE ([SumOfSales], Orders [Region] ="East" || Orders [Region]
="Central")
EastTechSales=
CALCULATE ([SumOfSales], Orders [Region] ="East", Orders [Category]
="Technology")
ALL
ALL Function returns all the rows in a table, or all the values in a column,
ignoring any filters that might have been applied.
This function is useful for clearing filters and creating calculations on all the
rows in a table or column.
Syntax
<Table> | <column>
The “table or column” that you want to clear filter on. If you want you can
add multiple columns to clear filter.
www.abtrainings.com
Power BI Analytics Benchmark (AB)
Trainings
Examples
Drag Category, Sales twice into Visuals. The Visual will give Below Output.
To get %Sales Go to the Field wells and Click on Expand button as shown below.
www.abtrainings.com
Power BI Analytics Benchmark (AB)
Trainings
Change “Show Value as” to “Percent of grand total” to get expected % Sales
results
ALLSELECTED
ALLSELECTED will returns all the rows in a table, or all the values in a
column, ignoring any filters that might have been applied inside the query or
Visualization, but keeping filters that come from outside slicer.
www.abtrainings.com
Power BI Analytics Benchmark (AB)
Trainings
When You Filter the Visual using the Slicer based on Region Column, you will
see the below results.
%SalesAllSelected =
[SumOfSales]/CALCULATE (SUM (Orders [Sales]), ALLSELECTED (Orders))
ALLEXCEPT
Removes all context filters in the table except filters that have been
applied to the specified columns.
www.abtrainings.com
Power BI Analytics Benchmark (AB)
Trainings
www.abtrainings.com
Power BI Analytics Benchmark (AB)
Trainings
RELATED
The RELATED function requires that a relationship exists between the current table
and the table with related information. You specify the column that contains the
data that you want, and the function follows an existing many-to-one relationship
to fetch the value from the specified column in the related table. If a relationship
does not exist, you must create a relationship.
Syntax
RELATED (<column>)
Example
Person = RELATED(People[Person])
***USERELATIONSHIP
NATURALINNERJOIN
www.abtrainings.com
Power BI Analytics Benchmark (AB)
Trainings
NATURALLEFTOUTERJOIN
CROSSJOIN
CALCULATETABLE
RELATEDTABLE
LOOKUPVALUE
Syntax
The value will return for result_column for the Rows where all pairs of
search_column and search_value have a match.
If there is no match a BLANK will return when You Don’t Supply Alternative Result, if
supplied Alternative Result will be returned.
If multiple rows match the search values and in all cases result_column
values are identical then that value is returned.
QtySold =
LOOKUPVALUE(Sales[QtySold],Sales[Category],Product[Category],Sales[ProductCod
e],Product[ProductCode])
CALCULATE
www.abtrainings.com
Power BI Analytics Benchmark (AB)
Trainings
CALCULATETABLE
FILTER
FILTER
CentralOrders = FILTER(Orders,Orders[Region]="Central")
Above Formula will create a New table with only Central Region Orders.
In many cases you can use the CALCULATE function instead of the FILTER
function to produce the same results (the resulting formula is usually easier to
understand, too).
www.abtrainings.com