0% found this document useful (0 votes)
166 views26 pages

My Power BI Report Is Slow - What Should I Do

Uploaded by

Rajat
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)
166 views26 pages

My Power BI Report Is Slow - What Should I Do

Uploaded by

Rajat
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/ 26

www.sqlbi.

com
My Power BI report is slow
What should I do?
Marco Russo, SQLBI
Mail: [email protected]
Twitter: @marcorus
We write We teach We provide We are recognized
Books Courses Consulting BI Experts
Remote
Consulting

Power BI/SSAS
Optimization

BI Architectural
Review

On-Site
Consulting

Custom Training
& Mentoring www.sq lb i.co m
Agenda

o Tools o Techniques

• DAX Studio • Know your data model


• VertiPaq Analyzer • Isolate query and measure
• Create repro query

4
The best all-in-one tool for developing DAX code

DAX Studio
DAX Studio

o http://daxstudio.codeplex.com
• Free add-in for Excel
• Standalone executable for
Tabular and Power BI
o It can query
• Analysis Services databases
• Power Pivot data models
• Power BI Desktop data models
• Both DAX and MDX queries
Main Features

o DAX Query Editor


• Full metadata available
• IntelliSense enabled
• Format DAX code
• Through www.daxformatter.com website
o Catch Query Plan and Server Timings
o Save query plan and timings for later analysis
Complete Demo

DAX Studio
Capturing Power BI queries using DAX Studio

o Create an empty page in Power BI


o Save Power BI file selecting empty page as the current one
o Close and open Power BI file
o Connect DAX Studio to Power BI
o Activate trace for All Queries in DAX Studio
o Switch report page in Power BI
o https://www.sqlbi.com/articles/capturing-power-bi-queries-using-dax-studio/
Know your data model first

o Do you know..
• The size in memory of each column
• The cardinality of each table
• The cardinality of each column
• Hint: they are not the same!
o VertiPaq Analyzer
• Simplify extraction of this data from DMVs
• http://www.sqlbi.com/tools/vertipaq-analyzer
Demo

VertiPaq Analyzer
Understanding Query Plans

o Logical Query Plan


• It is the logical flow of the query
• Fired as standard text
• Pretty hard to decode
o Physical Query Plan
• The logical query plan executed by the engine
• Can be very different from the logical one
• Uses different operators
o VertiPaq Queries
• Queries executed by the xVelocity engine
Tabular Two Engines

o Formula Engine (FE)


• Handles complex expressions
• Single threaded
o Storage Engine (VertiPaq / xVelocity) (SE)
• Handles simple expressions
• Executes queries against the database
• Multithreaded
The simplest query
Let’s profile a simple query to get acquainted with the DAX query engine

EVALUATE

ROW (
"Result",
SUM ( Sales[SalesQuantity] )
)
Profiler Information
What FE needed
from SE What SE
executed
Logical query plan

CPU Usage

Time spent in
SE

Physical query plan

Query Part of FE time


duration (not reliable)
Profiler Information
Formula Engine time computed as
Query Duration – Time spent in SE

704 - 696 = 8 milliseconds


CPU Usage

Time spent in
SE

Query Part of FE time


duration (not reliable)
Gathering meaningful numbers

o Values reported by the profiler might not be accurate on


a busy server
o Always test on a dedicated server
o If not available, your workstation is better
What is a Data Cache?
Column Storage Data Cache
Prod SUM(Amt) SUM(Qty)
Prod Amt Qty
Storage Engine (VertiPaq)
… … …
VertiPaq query (xmSQL) … … …
… … …
… … …

SE fills data
Result cache
Prod SUM(Amt) SUM(Qty)

… … …
… … …
FE works on
… … …
data caches
… … …
xmSQL

o Storage engine uses xmSQL


• Syntax similar to SQL
• Few options (compared to SQL)
• Not intended for the user
o Simple mathematical operations
o Some (not all) aggregations
o Usage of model relationships
How FE uses Data Caches

o There is no indication of which data cache is used by


which FE operator
o Only common sense and some geeky attitude helps
o For simple plans, it is easy
o For complex plans, it is nearly impossible
o Thus: optimize simple plans!
Cache
o DAX caches results of VertiPaq queries
• MDX caches measures too
o FE bound queries will not benefit from cache
Clear the Cache
Always remember to clear the cache prior to execute any performance test, otherwise numbers will be contaminated.
With DAX Studio it is a simple button click. With SSMS, you have to execute the following code snippet:

<Batch xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<ClearCache>
<Object>
<DatabaseID>Adventure Works DW Tabular</DatabaseID>
</Object>
</ClearCache>
</Batch>
Conclusions

Create a repro query


Isolate MDX or DAX query
Identify DAX expression (usually a measure)

Modify DAX expression and test different timings


DAX Studio improves productivity
Use local DAX measure overriding the one defined in the data model

23
References

o The Definitive Guide to DAX


By Marco Russo, Alberto Ferrari – Microsoft Press
http://www.sqlbi.com/books/the-definitive-guide-to-dax/

o Understanding DAX Query Plans


o http://www.sqlbi.com/articles/understanding-dax-query-plans/

o Understanding Distinct Count in DAX Query Plans


o http://www.sqlbi.com/articles/understanding-distinct-count-in-dax-query-plans/
Tools

o DAX Studio
o http://daxstudio.codeplex.com

o VertiPaq Analyzer
o http://www.sqlbi.com/tools/vertipaq-analyzer
Thank you!

Check our articles, whitepapers and courses on


www.sqlbi.com

You might also like