0% found this document useful (0 votes)
15 views37 pages

Avu Dax Formula Patterns

The document serves as a guide to DAX formula patterns in Power BI, covering various functions and concepts such as Time Intelligence, Filter Context, Row Context, and the CALCULATE function. It emphasizes the importance of understanding evaluation contexts and provides examples of key functions like RANKX, DIVIDE, and CONCATENATEX. Additionally, it encourages continuous learning and staying updated with Power BI features.

Uploaded by

harry.ha.1990
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views37 pages

Avu Dax Formula Patterns

The document serves as a guide to DAX formula patterns in Power BI, covering various functions and concepts such as Time Intelligence, Filter Context, Row Context, and the CALCULATE function. It emphasizes the importance of understanding evaluation contexts and provides examples of key functions like RANKX, DIVIDE, and CONCATENATEX. Additionally, it encourages continuous learning and staying updated with Power BI features.

Uploaded by

harry.ha.1990
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Power BI For Solving

Common Analytical
Problems
A Guide to DAX Formula Patterns
Time Intelligence
Used for time-based analysis, aggregating data over periods.

Example: TOTALYTD(Sales[Revenue], Date[Date])

Time functions often require a continuous date table for accuracy.

Watch out for leap years!

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


Filter Context
The set of filters actively applied to a calculation.

Code: CALCULATE(SUM(Sales[Revenue]), Sales[Country] = 'USA')

The CALCULATE function can modify the filter context.

Always ensure the right granularity when applying filters.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


Row Context
Refers to the current row during calculations in functions like SUMX or
FILTER.
Application: Using SUMX(FILTER(Sales, Sales[Revenue] > 1000),
Sales[Revenue]) to sum only high sales.

Created implicitly by iterators or explicitly using EARLIER().

Avoid nested row contexts to keep DAX efficient.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


RELATED & RELATEDTABLE
Retrieves related values from another table.

Code: RELATED(Product[Price])

Useful for looking up values in a normalized schema.

Ensure relationships are set up correctly.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


Evaluation Context
Determines the context in which DAX formulas are calculated.

Example: Context can be row or filter.

Mastery of context is key to DAX.

Understand the differences for accurate calculations.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


CALCULATE Function
Modifies the filter context.

Code: CALCULATE(SUM(Sales[Revenue]), ALL(Sales))

Most frequently used function in DAX.

It can override or add filters.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


ALL Function
Removes one or more filters.

Application: ALL(Sales[Product]) removes product filter.

Used to create 'All' level aggregates.

Avoid using without understanding its effect.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


EARLIER Function
Refers to the previous row context.

Code: Useful in nested calculations.

Often misunderstood, but powerful.

Commonly used in ranking.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


RANKX Function
Ranks values in a table.

Application: RANKX(ALL(Sales), Sales[Revenue])

Key for competitive analysis.

Watch out for ties in ranking.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


Variables
Store intermediate calculations.

Code: VAR avgSales = AVERAGE(Sales[Revenue])

Improves readability & performance.

Use extensively to break complex formulas.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


SWITCH Function
Alternative to nested IFs.

Application: SWITCH(TRUE(), Sales[Country]='USA', 'America',


Sales[Country]='UK', 'Europe')
More efficient than multiple IFs.

Can simplify logic dramatically.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


DIVIDE Function
Safe division, handles divisors of 0.

Code: DIVIDE(Sales[Revenue], Sales[Units])

Returns alternate result for divide by zero.

Safer than the '/' operator.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


BLANK Function
Represents no data or gaps.

Application: Used to handle missing values.

Not the same as NULL in SQL.

Can influence aggregations & visuals.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


Userelationship
Specifies a relationship for a calculation.

Code: CALCULATE(SUM(Sales[Revenue]), USERELATIONSHIP(Sales[Date],


'Date'[Date]))

For models with multiple relationships.

Only one relationship is active at a time.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


KEEPFILTERS
Preserves existing filters while adding new ones.

Application: CALCULATE(SUM(Sales[Revenue]),
KEEPFILTERS(Sales[Country]='USA'))

Modifies CALCULATE's default behavior.

Useful for nuanced filter scenarios.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


SUMMARIZE
Creates a summary table.

Code: SUMMARIZE(Sales, Sales[Country], 'Total Revenue',


SUM(Sales[Revenue]))

Powerful aggregation tool.

Can be resource-intensive.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


NATURALLEFTOUTERJOIN
Combines rows from two tables.

Application: Joining on common columns.

Resembles SQL's LEFT JOIN.

Be mindful of large tables.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


DATESYTD
Calculates Year to Date values.

Code: DATESYTD(Date[Date])

Essential for financial reporting.

Ensure continuous date table.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


SAMEPERIODLASTYEAR
Compares to the same period in the prior year.

Application: Year-over-year growth.

Critical for trend analysis.

Ensure date alignments.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


PATH Functions
Hierarchy & parent-child functions.

Code: PATH(Employee[EmpID], Employee[MgrID])

Useful for organizational charts.

Requires unique identifiers.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


CONTAINS Function
Checks for value in a table.

Application: CONTAINS(Sales, Sales[Product], 'Bike')

A lookup function.

Faster than using a filter.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


COALESCE Function
Returns first non-blank value.

Code: COALESCE(Sales[Discount], 0)

Handles missing data elegantly.

Can chain multiple columns.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


GENERATESERIES
Creates a table of numbers.

Application: GENERATESERIES(1,10,1)

Useful for creating sequences.

Can be used for date intervals.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


CROSSFILTER Function
Modifies relationship direction.

Code: CROSSFILTER(Sales[Date], Date[Date], None)

Can enable or disable relationships.

Advanced model manipulation.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


CONCATENATEX
Combines text values.

Application: CONCATENATEX(VALUES(Sales[Product]), Sales[Product], ', ')

Useful for creating lists.

Mind the delimiter.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


ISFILTERED & ISCROSSFILTERED
Checks for active filters.

Code: ISFILTERED(Date[Month])

Debugging and conditional logic.

Differentiate direct and indirect filters.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


TREATAS Function
Applies values as a filter.

Application: TREATAS({'USA', 'UK'}, Sales[Country])

Dynamic filtering technique.

Versatile for passing filters.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


FORMAT Function
Converts data types to text.

Code: FORMAT(Date[Date], 'MMM yyyy')

Custom date and number formatting.

Locale can affect results.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


ERROR Function
Returns a custom error.

Application: IF(SUM(Sales[Revenue]) < 0, ERROR('Negative Revenue'))

Data validation and alerts.

Use sparingly.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


CUBE Functions
Integrates DAX with MDX.

Code: Useful for BI tools integration.

Bridge between tabular & multidimensional.

Advanced topic.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


SELECTEDVALUE
Returns the selected value in a slicer.

Application: SELECTEDVALUE(Country[Name], 'All Countries')

Detects single selections.

Default value for multi-select.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


DATEDIFF
Calculates difference between dates.

Code: DATEDIFF(Date[StartDate], Date[EndDate], DAY)

Time duration calculations.

Supports days, months, and years.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


UNION, EXCEPT, INTERSECT
Combine tables with set operations.

Application: UNION(VALUES(Sales1[Product]), VALUES(Sales2[Product]))

SQL-like operations in DAX.

Ensure consistent schemas.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


X Functions (Iterators)
Perform row-wise calculations.

Code: SUMX(VALUES(Sales[Product]), Sales[Revenue] * Sales[Price])

Core concept in DAX.

Often resource-intensive.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


Continuous Learning
Stay updated with Power BI updates. Exploring new features in
the latest version. Engage in Enterprise DNA forum.

FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI


FUTURE-PROOF YOUR CARREER MASTER DATA SKILLS UPSKILL IN AI

ENTERPRISEDNA.CO

You might also like