1. Trang chủ
  2. » Thể loại khác

Power pivot and power BI

330 41 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 330
Dung lượng 14,94 MB
File đính kèm Power Pivot and Power BI.rar (14 MB)

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Cấu trúc

  • Front Cover

  • Back Cover

  • Preface/Forward/Intro

  • Dedications

  • Supporting Workbooks and Data Sets

  • Errata and Book Support

  • A Note on Hyperlinks

  • Foreword and Forward

  • Introduction - Our Two Goals for this Book

  • 1 - A Revolution Built On YOU

  • 2 - Power Pivot and the Power BI Family: Making Sense of the Various Versions

  • 3 - Learning Power Pivot “The Excel Way”

  • 4 - Loading Data Into Power Pivot

  • 5 - Intro to Calculated Columns

  • 6 - Introduction to DAX Measures

  • 7 - The “Golden Rules” of DAX Measures

  • 8 - CALCULATE() – Your New Favorite Function

  • 9 - ALL() – The “Remove a Filter” Function

  • 10 - Thinking in Multiple Tables

  • 11 - “Intermission” – Taking Stock of Your New Powers

  • 12 - Disconnected Tables

  • 13 - Introducing the FILTER() Function, and Disconnected Tables Continued

  • 14 - Introduction to Time Intelligence

  • 15 - IF(), SWITCH(), BLANK(), and Other Conditional Fun

  • 16 - SUMX() and Other X (“Iterator”) Functions

  • 17 - Multiple Data Tables

  • 18 - Multiple Data Tables – Differing Granularity

  • 19 - Performance: Keep Things Running Fast

  • 20 - Power Query to the Rescue

  • 21 - Power BI Desktop

  • 22 - “Complicated” Relationships

  • 23 - Row and Filter Context Demystified

  • 24 - CALCULATE and FILTER – More Nuances

  • 25 - Time Intelligence with Custom Calendars: Greatest Formula in the World

  • 26 - Advanced Calculated Columns

  • 27 - New DAX Functions… and Variables!

  • 28 - “YouTube for Data” – The Importance of a Server

  • PS: Can We Ask You for a Special Favor?

  • A1 - Power Pivot and SSAS Tabular: Two Tools for the Price of One (again!)

  • A2 - Cube Formulas – the End of GetPivotData()

  • A3 - Some Common Error Messages

  • A4 - People: The Most Powerful Feature of Power Pivot

  • Index

  • Power Pivot and Power BI

  • Dedications

  • Supporting Workbooks and Data Sets

  • Errata and Book Support

  • A Note on Hyperlinks

  • Foreword and Forward

    • “State of the Union” November 2015 – What’s Changed?

    • What Has Changed at Microsoft? Virtually Everything.

    • What’s Changed in My Corner of the World? Also Everything.

  • Introduction - Our Two Goals for this Book

  • 1 - A Revolution Built On YOU

    • Does This Sound Familiar?

    • Excel Pros: The World Is Changing in Your Favor

    • Our Importance Today

      • Excel at the Core

    • Three Ingredients of Revolution

      • Ingredient One: Explosion of Data

      • Ingredient Two: Economic Pressure

      • Ingredient Three: Dramatically Better Tools

  • 2 - Power Pivot and the Power BI Family: Making Sense of the Various Versions

    • It’s a Family of Products Built on Shared Engines

      • Power Query is a Close Second in Importance

    • Visuals: The Crucial “Last Mile”

    • Power BI Desktop: Two Tools for the (Learning) Price of One!

      • Same Engines, Just Different Visuals

      • What do we mean by the “tough” or “valuable” stuff?

    • Power Pivot (in Excel) Versions

      • Power Pivot for Excel 2010

      • Power Pivot for Excel 2013 - Only Available in “Pro Plus” Excel

    • Differences in User Interface: 2010, 2013, 2016

      • When We Said “Cosmetic” We Meant “Awkward”

    • 32-bit or 64-bit?

    • Office 2010 or Newer is Required

    • Power Pivot is Like Getting Fifteen Years of Excel Improvements All at Once

    • Learn Power Pivot As You Learned Excel: Start Simple & Grow

    • When to Use Power Pivot, and How it Relates to Normal Pivot Usage

      • What This Book Will Cover in Depth

  • 4 - Loading Data Into Power Pivot

    • No Wizards Were Harmed in the Creation of this Chapter

    • Everything Must “Land” in the Power Pivot Window

      • Launching the Power Pivot Window

      • One Sheet Tab = One Table

      • You Cannot Edit Cells in the Power Pivot Window

      • Everything in the Power Pivot Window Gets Saved into the Same XLSX File

    • Many Different Sources

    • Linked Tables (Data Source Type)

      • Advantages

      • Limitations

      • Tips and Other Notes

    • Pasting Data Into Power Pivot (Data Source Type)

      • Advantages

      • Limitations

    • Importing From Text Files (Data Source Type)

      • Advantages

      • Limitations

    • Databases (Data Source Type)

      • Advantages

      • Limitations

    • Less Common Data Source Types

      • SharePoint Lists

      • Reporting Services (SSRS) Reports

      • Cloud Sources Like Azure DataMarket and SQL Azure

      • “Data Feeds”

    • Other Important Features and Tips

      • Renaming up Front – VERY Important!

      • Don’t Import More Columns than You Need

      • Table Properties Button

      • Existing Connections Button

  • 5 - Intro to Calculated Columns

    • Two Kinds of Power Pivot Formulas

    • Adding Your First Calculated Column

      • Starting a Formula

      • Referencing a Column via the Mouse

      • Referencing a Column by Typing and Autocomplete

      • Just like Excel Tables!

      • Rename the New Column

      • Reference the New Column in Another Calculation

    • Properties of Calculated Columns

      • No Exceptions!

      • No “A1” Style Reference

      • Stored Statically with the File

    • Slightly More Advanced Calculations

      • Function Names Also Autocomplete

      • Aggregation Functions Implicitly Reference the Entire Column

      • Quite a Few “Traditional” Excel Functions are Available

      • Excel functions Are Identical in Power Pivot

    • Enough Calculated Columns for Now

  • 6 - Introduction to DAX Measures

    • “The Best Thing to Happen to Excel in 20 Years”

    • Aside: A Tale of Two Formula Engines

    • Adding Your First Measure

      • Create a Pivot

      • Add a Measure!

      • Name the Measure

      • Results

      • Works As You Would Expect

    • “Implicit” Versus “Explicit” Measures

    • Referencing Measures in Other Measures

      • Another Simple Measure First

      • Creating a Ratio Measure

      • Original Measures Do NOT Have to Remain on the Pivot

      • Changes to “Ancestor” Measures Flow Through to Dependent Measures

      • Cases Where This Makes Real Sense

      • Reuse Measures, Don’t “Redefine”

    • Other Fundamental Benefits of Measures

      • Use in Any Pivot

      • Centrally-Defined Number Formatting

    • Whetting Your Appetite: COUNTROWS() and DISTINCTCOUNT()

      • COUNTROWS(Sales)

      • DISTINCTCOUNT(Sales[OrderDate])

      • Deriving More Useful Measures From These Two

      • Rearrange Pivot, Measures Automatically Adjust!

    • Slicers in Different Versions of Excel

    • Measures Are “Portable Formulas”

  • 7 - The “Golden Rules” of DAX Measures

    • How Does the DAX Engine Arrive at Those Numbers?

      • Stepping Through That Example

    • Translating the Examples Into Three Golden Rules

      • Rule A: DAX Measures Are Evaluated Against the Source Data, NOT the Pivot

      • Rule B: Each Measure Cell is Calculated Independently

      • Rule C: DAX Measures are Evaluated in 6 Logical Steps

        • Step 1: Detect Pivot Coordinates

        • Step 2: CALCULATE Alters Filter Context

        • Step 3: Apply Those Filter Coordinates to the Underlying Table(s)

        • Step 4: Filters Follow the Relationship(s)

        • Step 5: Evaluate the Arithmetic

        • Step 6: Return Result

    • How the DAX Engine Calculates Measures

      • No “Naked Columns” in Measure Formulas

      • Best Practice: Reference Columns and Measures Differently

      • Best Practice: Assign Measures to the Right Tables

  • 8 - CALCULATE() – Your New Favorite Function

    • A Supercharged SUMIF()

      • CALCULATE() Syntax

      • CALCULATE() in Action – a Few Quick Examples

    • How CALCULATE() Works

    • Two Useful Examples of CALCULATE()

      • Example 1: Transactions of a Certain Type

      • Example 2: Growth Since Inception

    • Alternatives to the “=” Operator in <Filters>

    • Evaluation of Multiple <filters> in a Single CALCULATE()

    • The “ALL” (aka “Unfiltered”) Filter Context

      • Not all Totals Are Completely (or Even Partially) Grand

  • 9 - ALL() – The “Remove a Filter” Function

    • The Crisp Basics

    • The Practical Basics – Two Examples

      • Example 1 – Percentage of Parent

      • Example 2 – Negating a Slicer

    • Variations

    • ALLEXCEPT()

    • ALLSELECTED()

  • 10 - Thinking in Multiple Tables

    • A Simple and Welcome Change

    • Unlearning the “Thou Shalt Flatten” Commandment

    • Relationships Are Your Friends

    • “Lookup” Tables

      • The Diagram View

      • Using Related Tables in a Pivot

      • Why That Works: Filter Context “Travels” Across Relationships

      • Visualizing Filters Flowing “Downhill” – One of Our Mental Tricks

    • Filters from All Related Lookup Tables Are Applied

    • CALCULATE() <Filters> Also Flow Across Relationships

  • 11 - “Intermission” – Taking Stock of Your New Powers

  • 12 - Disconnected Tables

    • A Parameterized Report

      • Adding the Parameter Table

      • Adding a “Parameter Harvesting” Measure

      • The Field List is Grumpy About This

      • Using the Parameter Measure for Something…Useful

      • Parameter Table Can Be Used on Rows and Columns Too!

      • Why is it Important That They Be Disconnected?

      • A Very Powerful Concept

    • Disconnected Table Variation: Thresholds

      • Create a Disconnected Table to Populate the Slicer:

      • Write a Measure to “Harvest” the User’s ­Selection:

      • Diverging From the Prior Example: We Need to Filter, Not Perform Math

      • CALCULATE() Has a Limitation? Not really.

  • 13 - Introducing the FILTER() Function, and Disconnected Tables Continued

    • When to Use FILTER()

    • FILTER() Syntax

    • Why is FILTER() Necessary?

      • It’s All About Performance (Speed of Formula Evaluation)

      • How to Use FILTER() Carefully

    • Applying FILTER() in the “Thresholds” Example

      • Revisiting the Successful Formula

      • Verifying That the Measures Work

      • This Could Not Be Done with Relationships

      • Tip: Measures Based on a Shared Pattern – Create via Copy/Paste

    • More Variations on Disconnected Tables

      • Upper and Lower Bound Thresholds

      • Fixing the Sort Order on the Slicer: The “Sort By Column” Feature

      • Completing the Min/Max Threshold

      • A Way to Visualize Disconnected Tables

    • Putting This Chapter in Perspective

  • 14 - Introduction to Time Intelligence

    • At Last, It is Time!

    • “Standard Calendar” versus “Custom Calendar”

      • Standard Calendars: The Focus of This Chapter

      • Custom Calendars: Perhaps Even More Important than Standard (Covered Later)

    • Calendar: A Very Special Lookup Table

      • Where to Get a Calendar Table

      • Properties of a Calendar Table

      • Our Calendar table: Imported and Related

      • Operates like a Normal Lookup Table

    • First Special Feature: Enable Date Filtering via Mark as Date Table

    • Second Special Feature: Time Intelligence Functions!

      • Diving in with DATESYTD()

      • Anatomy of DATESYTD()

        • Function Definition

        • How Does it Work?

        • Changing the Year-End Date

      • DATESMTD() and DATESQTD() – “Cousins” of DATESYTD()

      • TOTALYTD() – Another Cousin of DATESYTD()

    • The Remaining (Many) Time Intelligence Functions – Grouped Into “Families”

    • FIRSTDATE() and LASTDATE()

    • ENDOFMONTH(), STARTOFYEAR(), etc.

    • DATEADD()

      • Growth Versus Last Year (Year-Over-Year, YOY, etc.)

      • Quirks and Caveats

        • You Must Have Contiguous Date Ranges on Your Pivot

        • DATEADD() Has Special Handling for “Complete” Months/Quarters/Years

        • DATEADD() Lacks Intelligence for Weeks

    • SAMEPERIODLASTYEAR()

    • PARALLELPERIOD(), NEXTMONTH(), PREVIOUSYEAR(), etc.

      • PARALLELPERIOD()

      • NEXTMONTH(), PREVIOUSYEAR(), etc.

    • DATESBETWEEN()

      • “Life to Date” Calculations

      • Removing That Hardwired 1/1/1900

      • DATESBETWEEN() is Fantastic with Disconnected Tables Too!

  • 15 - IF(), SWITCH(), BLANK(), and Other Conditional Fun

    • Using IF() in Measures

    • The BLANK() Function

    • DIVIDE() Function

    • The ISBLANK() Function

    • HASONEVALUE()

    • IF() Based on Row/Column/Filter/Slicer Fields

      • The VALUES() Function

      • Using VALUES() for Columns That Are Not on the Pivot

      • VALUES() Only Returns Unique Values

    • SWITCH()

      • SWITCH TRUE()

  • 16 - SUMX() and Other X (“Iterator”) Functions

    • Need to Force Totals to Add Up “Correctly?”

    • Anatomy of SUMX()

    • SUMX() in Action

      • Detailed Stepthrough

    • MINX(), MAXX(), AVERAGEX()

    • FILTER()

    • COUNTX() and COUNTAX()

      • Why is This Different From COUNTROWS(), Then?

      • COUNTAX() versus COUNTX()

    • Using the X Functions on Fields That Aren’t Displayed

      • But Which Country?

    • RANKX()

      • The Use of ALL()

      • Ties

      • The Optional Parameters

      • Duplicate FullNames?

    • TOPN()

    • Non-Measure Second Arguments to the X Functions

      • The COUNTAX() Mystery Solved!

  • 17 - Multiple Data Tables

    • Service Calls

    • Service Calls and Sales Mashup

      • In Traditional Excel

      • Do Not “Flatten”

      • Measures from Different Data Tables in the Same Pivot!

      • Hybrid Measures

    • Multiple Data Tables Gotchas

      • Using Fields from Lookup Table vs. the Data Table

      • Data Table Connected to Some but Not All Lookup Tables

        • Staying Out of Trouble

  • 18 - Multiple Data Tables – Differing Granularity

    • Example1: Budget versus Actuals

      • Difficult in Normal Excel

      • Much Faster and More Flexible in Power Pivot

      • Creating Relationships – We Need Some New Lookup Tables

      • Where Do We Get This New Lookup Table? Consider a Database or Power Query

      • SalesTerritory is at Same Granularity Already

      • Repeating the “New Table” Process for Calendar

      • Integrated Pivot

      • Hybrid Measures with Data at Different Grain

    • Example 2: Using that Mysterious RANKX() Third Argument

      • The Problem: Ranking MY Products Against Theirs!

      • Year Granularity Mismatch Means a New Lookup Table

      • Simple Measure

      • Now the Absolutely Amazing “Cross-Rank” Measure

      • And Since Both Are Filtered by the Years Table…

  • 19 - Performance: Keep Things Running Fast

    • How Important is Speed?

      • "Now" Is Three Seconds in Length

      • What Happens When Something Takes Longer Than Three Seconds?

    • Slicers: The Biggest Culprit

      • “Cross-Filtering” Behavior

      • Cross-Filtering is Expensive in Terms of Performance

      • Mitigating the Effects of Cross-Filtering

        • How to Turn off Cross-Filtering

        • Turning off Cross-Filtering Only Impacts that Slicer

        • Slicers For Which You Should Turn Cross-Filtering Off

    • The Shape of Your Source Tables Is Also Important

      • Narrower Tables are Better

      • Imported Columns Are Generally Better than Calculated Columns

      • “Star Schema” is Generally Better than “Snowflake Schema”

    • Measure Performance

      • DISTINCTCOUNT() is Much Faster than COUNTROWS(DISTINCT())

      • FILTER() Should Only Be Used Against Lookup Tables and Other “Small” ​Columns

      • Remember That the “X” Functions Are Loops

  • 20 - Power Query to the Rescue

    • Power Query: Bring Order to Messy Data

    • #1 - Appending Files to Create a Single Power Pivot Table

      • Scenario

        • Connecting to One of the CSV Files

        • Adding a Custom Column to “Tag” This File

        • Loading the Data into Power Pivot

        • Connecting to the Second CSV File

        • Connecting to the Third CSV File

        • Time for the Append!

        • “Keeping” Only the Appended Query

        • Testing Refresh

      • Why This Is a Major Benefit

    • #2 - Combine Multiple Files from a Folder into a Single Table

      • Scenario

        • From Folder

        • Combine CSV Files

        • First Row As Headers

        • Change Data Type and Remove Errors

        • Testing Refresh

      • Why This Is a Major Benefit

    • #3 – Adding Custom Columns to Your Lookup Tables

      • Scenario

        • Get Data

        • Add Custom Column

        • Define Custom Formula

      • Why This Is so Amazing

    • #4 - Using Power Query to “Unpivot” a Table

      • Scenario

        • Get Data from Excel

        • Header Row Handling and Remove Column

        • Unpivot!

        • Rename and Change Type

      • Why This Is a Major Benefit

    • #5 - Using Power Query to Create a Lookup Table from a Table

      • Scenario

        • Create Lookup Table

        • Create Data Table

        • Relating the Two Tables

      • Why This Is so Amazing

    • #6 - Creating a Calendar Table: Advanced Power Query

      • “Wait, I Don’t See a ‘Make Calendar’ Button!”

      • Steps

      • Why This Is a Major Benefit

    • How NOT to Use Power Query

      • Don’t Use Power Query Without Power Pivot

        • Don’t Use Power Query Calculations as a Substitute for DAX Measures

        • Don’t Use Power Query to Flatten Tables

        • Don’t Use Power Query to Mash Two Data Tables Together

  • 21 - Power BI Desktop

    • Meet the New Kid On the Block

      • Tons of Visualizations

        • Creating Reports is Easy as 1-2-3

        • Fully-Interactive Reports Make Your Data Come to Life

        • Power Pivot, Power Query and Power View++ All in One Package

      • Download Today!

    • Remember: Same Engines, Different Visuals

    • A Few Words of Perspective

      • You’re Probably Going to Use Both

      • The “Sales Pitch” – Show Excel-Based to the Analysts, Desktop to Execs

    • The “Tour”

      • Missing Terminology

      • The Different Modes

      • Get Data (a.k.a. Power Query)

      • Data Model (a.k.a. Power Pivot)

      • Reports (a.k.a. Power View, but Much Better!)

      • Import Existing Excel Power Pivot Models!

      • Sharing Power BI Desktop Files

  • 22 - “Complicated” Relationships

    • Multiple Relationships Between the Same Two Tables

      • USERELATIONSHIP()

    • Many to Many Relationships

      • First, a Bad Example

      • Another Bad Example

      • Real-World Overlap: The Source of “Legit” Many-to-Many

      • “Bridge” Table

      • Apply M2M as a Pattern

    • Power BI Desktop

  • 23 - Row and Filter Context Demystified

    • The Basics: Gateway to Doubling Your Superpowers

      • The Simple Definitions

      • Row Context: The Key Ingredient of Calc Columns

      • There’s No Row Context in Measures!

      • Filter Context: The Key Ingredient of Measures

      • There’s No Filter Context in Calc Columns!

      • Recap So Far

    • Interaction with Relationships

      • Relationships and Filter Context

      • Relationships and Row context

    • Exceptions and Overrides!

      • Iterator Functions Create Row Context During Measure Calculation

      • CALCULATE Creates Filter Context in Calc Columns

      • We can use CALCULATE to “follow” relationships in calc columns

      • Using Measures Within a Row Context: a Genuine Curveball

    • Putting It All Together: Review Example

      • Why Did Our Original Measure Work to Begin With?

      • Recap Within the Context of FILTER()

      • In Case of Emergency…

    • Key Points from This Chapter

  • 24 - CALCULATE and FILTER – More Nuances

    • CALCULATE Filter Arguments Override Pivot Filters

    • The “Secret” Second Purpose of ALL(), FILTER(), Etc.

      • CALCULATE’s Definition Gives Us a Hint!

      • ALL() Is the “Remove Filters” Function, but it’s Also a Table!

      • There Are Dozens of These Dual-Purpose Functions!

      • Could Have Been Separate Functions?

    • Nesting Table Functions Inside One Another

      • FILTER Can Unfilter?

    • Putting it All Together

  • 25 - Time Intelligence with Custom Calendars: Greatest Formula in the World

    • Perhaps Our Favorite Thing in DAX

    • Custom Calendars

      • The Periods Table - a “4/4/5” Example

      • How This Changes Things: We Need to “Write” Our Own Time Intelligence Functions

    • Connecting the Periods Table

    • Simple “Sales in Period” Measure

    • Another Familiar Concept: Sales per Day

    • First New Concept: Sales per Day in Prior Period

      • Getting Organized First

      • Desired Results

    • The Greatest Formula in the World

      • “Clear Filters Then Re-Filter” – Another Name for GFITW

      • Clear Filter

      • Re-Filter: Navigation Arithmetic

        • Table[Column] Uses Row Context Generated by FILTER

        • MAX() Operates Over a Filter Context

      • In Your Periods Table, You Always Need a Numeric PeriodID Column or Equivalent

    • More GFITW measures – Year Over Year and Year To Date

      • Prior Period Sales

      • Year Over Year (YOY) Custom Calendar Measure

      • Year To Date (YTD) Measure with Custom Calendar

    • Fixing Measures to Work at Total Level

      • Suppressing Prior Period for Totals

      • Fixing YOY to Work at Total Level

        • The Fix

      • Fixing Prior Period to Work on Totals, Too

    • The Usual “Percent Growth” Formulas

  • 26 - Advanced Calculated Columns

    • Perspective: Calculated Columns Are Not DAX’s Strength!

      • OK, Power Pivot Calc Columns Are a Strength in Some Ways.

      • But More Difficult in Some Cases

    • Start Out With “Not so Advanced”

      • Grouping Columns

      • Unique Columns for Sorting

      • Another Sort by Column Example

    • Now For the Advanced Examples

      • Summing up in a Lookup Table

      • Use of the EARLIER() Function

        • EARLIER() in Action

      • An Even More Advanced Example

    • Calculated Columns are Static

    • Memory and CPU Consumption During Recalculation of Complex Calc Columns

  • 27 - New DAX Functions… and Variables!

    • Amazing Since 2010, and STILL Improving

    • Important Note: Excel 2016+ and Power BI Desktop Only!

    • New Functions – Some Highlights

      • DATEDIFF()

      • MEDIAN() and PERCENTILE

      • PRODUCT()

      • GEOMEAN() and GEOMEANX()

      • Other Corresponding X Functions

      • CONCATENATEX: The Most Interesting Function in the World?

      • ISEMPTY()

      • INTERSECT(), EXCEPT() and UNION()

        • INTERSECT()

        • EXCEPT()

        • UNION()

      • More New Functions

    • DAX Variables

      • Variables Are like a Tape Recorder

      • Variables Offer Three Benefits

      • Benefit One: Cleaner Formulas

      • The VAR Keyword

      • The RETURN Keyword

      • Referencing a Variable

      • Cleaner Formulas (Benefit One) Revisited

      • Benefit Two: Less “Mysterious” Formulas

        • Example 1: Alternative to EARLIER?

        • Example 2: Measure References Inside FILTER (Within a Measure)

  • 28 - “YouTube for Data” – The Importance of a Server

    • Files – Great for Storage, Not Great for Sharing

      • Email Sucks as a Delivery Vehicle for Our Awesome Work!

      • Network Distribution via File Shares? Not much better.

      • Parallels to Video Files, Circa 1998

        • Parent, Grandparents, and Pictures of Cats

        • YouTube Happens!

        • Importance of Web/Mobile

    • So We Need “YouTube for Data”

      • PowerBI.com Quick Tour

        • Step 1: Upload XLSX/PBIX File to PowerBI.com

        • Step 2: Sharing Your Dashboard

    • Cloud/Server Option Comparison

      • Cloud/Server Sharing Option: Even More Valuable than YouTube

  • PS: Can We Ask You for a Special Favor?

  • A1 - Power Pivot and SSAS Tabular: Two Tools for the Price of One (again!)

    • SSAS Tabular Features

    • Power Pivot to SSAS Tabular

      • Connect to SSAS Tabular from Excel

    • Going Further with SSAS Tabular: Visual Studio

    • Key Takeaways

  • A2 - Cube Formulas – the End of GetPivotData()

    • Formulas Reaching into Pivots = The Dark Ages

    • One Click That Will Change Your Life

    • The Data Is Still “Live!”

    • You Can Also Write Them “From Scratch”

      • For Starters, CUBEVALUE() Is All You Really Need

      • Adding a Slicer is easy…

    • Perspective – When to Use, Tradeoffs, Etc.

    • More Information

  • A3 - Some Common Error Messages

    • Addin is “Out of Sync”

    • “Initialization of the Data Source Failed”

    • Other Scary-But-Harmless Errors

    • Perspective

  • A4 - People: The Most Powerful Feature of Power Pivot

  • Index

Nội dung

Detect Pivot Coordinates

Before the DAX engine even looks at your formula, it de- tects the “coordinates” of the current measure cell (the

Values-area cell from the pivot that is currently being calculated.)

To illustrate this, let’s use a slightly “richer” pivot:

The selected measure cell has three “coordinates”, com- ing in from the Row, Column and the Slicer –

When specifying pivot coordinates, use the Table[Column] format, as it may appear redundant initially but will prove useful when working with multiple tables.

A measure cell’s set of filter coordinates is often referred to as its Filter Context

CALCULATE Alters Filter Context

We will revisit this topic later in the book for a more comprehensive explanation For now, we mention it briefly to ensure consistency in the numbering of the steps throughout the text.

Apply Those Filter Coordinates to the Underlying Table(s)

The specified filters in the filter context are applied exclusively to the Sales table, as all three coordinates originate from it This filtering process occurs behind the scenes, affecting the Sales table based on the MonthNum, Year, and ProductKey values in the filter context.

Figure 107 Applying Filter Coordinates in Step 3: All Three Filters Get Applied to the Sales Table

Filters Follow the Relationship(s)

Covered in Chapter 10 We’ll skip this for now, too.

Power Pivot and Power BI: The Excel User's Guide to the Data Revolution

Evaluate the Arithmetic

The arithmetic in your formula is evaluated only after the filter context of a measure cell, defined by its position in the pivot, has been applied to filter the underlying table(s).

In our example, the calculation is straightforward: SUM(Sales[SalesAmt]), but more complex calculations would operate similarly on the filtered rows Essentially, functions like SUM() or COUNTROWS() are executed only after the filter context has been applied to the source tables.

Figure 108 Evaluate the arithmetic against all the rows that “survived” the filtering process

In Step 3, while the Sales[SalesAmt] column itself wasn't directly filtered, applying filters to the [ProductKey], [MonthNum], and [Year] significantly reduced the total number of rows in the Sales table Consequently, the [SalesAmt] column now reflects only a subset of its overall values, highlighting the interconnectedness of data filtering in analysis.

Return Result

The result of the arithmetic is returned to the current measure cell in the pivot, then the process starts over at step 1 for the next measure cell.

Figure 109 Result is returned back to the Pivot

The evaluation process consists of two distinct phases: the application of filters followed by arithmetic calculations This can be visualized as an assembly line with two machines, where the first is the Filter Machine and the second is the Math Machine.

Figure 110 Some people find it helpful to visualize the calculation process as an assembly line: first things go into the Filter Ma- chine, then the Math Machine.

How the DAX Engine Calculates Measures

Here is a recap of all six golden rules, which outline how the DAX engine works:

Figure 111 Measure evaluation proceeds as per steps outlined Details on some steps to be filled-in in later chapters A Few More

No “Naked Columns” in Measure Formulas

In a measure formula, referencing a column must always be done within a function; otherwise, a direct reference will result in an error For instance, using a column reference without wrapping it in a function is not permitted.

[My New Measure] Sales[Margin]

Figure 112 We enter a “naked” column reference into the measure editor, then click Check Formula…

Power Pivot and Power BI: The Excel User's Guide to the Data Revolution

Figure 113 …leading to a relatively cryptic error message.

Let’s look at that error message:

A calculation error has occurred in the 'Sales' measure, indicating that the value for the 'Margin' column cannot be determined in the current context It's essential to verify that all columns referenced in the calculation expression are present and ensure there are no circular dependencies affecting the calculation.

The error message is not very informative; it should provide more guidance When encountering this error, it's essential to interpret it as an indication that there is an unqualified column reference present in your code.

“Cannot be determined in the current context” should become a trigger phrase for you to think “I have a naked column reference somewhere in my measure formula.”

But all of the following would be valid:

Aggregation functions are essential in pivot tables, as they transform sets of rows into concise numerical summaries Calculated column formulas utilize "naked columns," while measures serve as aggregations that cannot independently reference naked columns.

Remember, naked column references are OK in calculated columns This rule only applies to measures.

Best Practice: Reference Columns and Measures Differently

Whenever we are writing a measure formula,

• To reference a column, we include the table name: TableName[ColumnName]

• To reference a measure, we omit the table name: [MeasureName]

To enhance the readability of our formulas, we use a naming convention where references with a table name indicate a column, while those without a table name signify a measure.

Additionally, there are many situations in which omitting the table name on a column reference will return an error Following this best practice avoids that issue as well.

Best Practice: Assign Measures to the Right Tables

The “Table name” box in the measure editor controls which table the measure will be assigned to in the field list.

Figure 114 If you set this dropdown to the Sales table…

Figure 115 …the measure will be “parented” to the Sales table in the field list.

Simple Rule: We assign our measures to the tables that contain the numeric columns used in the formula

This is merely good hygiene so that your model is easier to understand later (by you or by someone else)

When assigning a measure that returns values from the Sales table, it is crucial to keep it linked to the Sales table to avoid confusion with customer metrics Assigning it to the Customers table could lead to misunderstandings, as it may imply an evaluation of customer numbers instead of sales figures It's important to note that the table to which a measure is assigned does not affect the results; the outcomes remain consistent regardless of the assignment.

Power Pivot and Power BI: The Excel User's Guide to the Data Revolution

8 - CALCULATE() – Your New Favorite Function

Have you ever used the Excel function SUMIF(), or perhaps its newer cousin, SUMIFS()?

We describe CALCULATE() as “the SUMIF/SUMIFS you always wish you’d had.” You are going to love this function, be- cause it works wonders

If you've been fortunate enough to bypass the SUMIF() and SUMIFS() functions in Excel, it's time to recognize their value These powerful functions allow you to sum a specified column while excluding rows that do not meet your defined criteria For example, you can utilize SUMIF to calculate the total sales figures for entries where the Year column indicates 2012.

Does that sound familiar? It sounds a lot like the Golden Rules from the prior chapter – “filter, then arithmetic.” An interesting similarity, and CALCULATE() continues in that same tradition.

Anyway, CALCULATE() is superior to SUMIF() and SUMIFS() in three fundamental ways:

1 It has cleaner syntax This is the smallest of the three advantages, but it feels good And a happier formula writer is a better formula writer.

In Excel, the absence of specific functions like MAXIF(), MINIF(), and STDEVIF() can be frustrating, as users often seek more versatile conditional calculations However, the CALCULATE() function provides a powerful solution by enabling users to apply any aggregation function or complex multi-function expression, effectively creating an IF version for a wide range of scenarios.

3 It can be used in pivots (as part of a measure), which normal SUMIF() cannot.

CALCULATE(, , , …)

Ex: CALCULATE(SUM(Sales[Margin]), Sales[Year] 01)

Ex: CALCULATE([Sales per Day], Sales[Year] 02, Sales[ProductKey]13)

CALCULATE() in Action – a Few Quick Examples

Let’s start with a simple pivot Year on rows, [Total Sales] measure on values:

OK, let’s add a new measure, one that is always filtered to Year 02:

[2002 Sales] CALCULATE ( [Total Sales], Sales[Year] = 2002 )

Three things to note in this formula:

In the CALCULATE function, the argument can accept any valid measure name, including pre-defined measures and formula expressions suitable for defining a measure.

2 In the argument, 2002 is not in quotes That’s because the

Year column is numeric If it were a text column, we would have need- ed to use =”2002” instead.

3 We only used one argument this time, but we could use as many as we want in a single CALCULATE formula.

Figure 116 Simple pivot – the basis for our first foray into CALCULATE()

Figure 117 Our new measure matches the original measure’s 2002 value in every situation!

The results may align closely with your expectations, though they might not be exactly what you anticipated You may have expected the years 2001 and 2003 to show zeroes for the new measure, and the grand total cell might be puzzling However, it’s likely intuitive that the new measure consistently reflects the 2002 value from the original measure.

Typically, writing a CALCULATE measure that filters a column present in the pivot, such as Sales[Year], is uncommon and often lacks practical application This approach is introduced here to illustrate the concept effectively.

To enhance clarity, we can replace the Year with MonthNum in the pivot, which offers a more logical representation of the data While the overall total remains at $6.5 million, each individual cell now reflects unique sales figures for 2002 corresponding to the MonthNum from the pivot.

Figure 118 Previous results examined: each month of 2002 is returned separately, and the grand total matches all of 2002 Exactly what we want and expect!

To understand the functionality of CALCULATE(), it's essential to analyze its mechanics, as this will clarify some of the surprising outcomes observed in the initial example.

There are three key points to know about CALCULATE(), specifically about the arguments:

The arguments play a crucial role during the "filter" phase of measure calculation by altering the filter context provided by the pivot This modification occurs prior to the application of filters to the source tables and before the arithmetic phase takes place.

Ngày đăng: 26/08/2021, 22:44

TỪ KHÓA LIÊN QUAN