= if ( factresellersales[discountedprice]
TRANSCRIPT
![Page 1: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/1.jpg)
![Page 2: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/2.jpg)
Budgeting Solution Built with PowerPivotAlberto FerrariBI Architect and ConsultantSQLBI.COM
SESSION CODE: BIU02
![Page 3: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/3.jpg)
Who am I?
[email protected] Independent consultant10+ years on SQL Server5+ years on BI & OLAPBook author
Expert Cube Development with Microsoft SQL Server Analysis ServicesPowerPivot for Excel 2010:Give your data a meaning
Founder of SQLBI.COM
![Page 4: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/4.jpg)
Agenda
From the user point of view…Focus on common PowerPivot data models
Ratios and PercentagesBanding (discretization)Simulations (Courier Simulations)Non additive measures (Current account balance)Dynamic Sets
In the meantimeSome insights into the DAX programming language
![Page 5: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/5.jpg)
Ratios and PercentagesHow to compute ratios and percentages
![Page 6: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/6.jpg)
What is a filter context?
Each cell, in a pivot table, defines a filter context
During cell evaluation, the whole database is filtered with the filter context, rows outside it are not considered.
(Australia, 2001)
![Page 7: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/7.jpg)
The background
A ratio need to «exit» from the filter context
Ratio = divide the «part» over the «whole»But… The filter context hides the «whole»…
(Australia, 2001) (2001)
![Page 8: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/8.jpg)
The solution: change the filter context with ALL
We need to define a new measureBased on CALCULATE
We create e new context for a specific dimensionIn order to make it consider all the values for that dimension
Perc = SUM(FactInternetSales[SalesAmount]) / CALCULATE ( SUM (FactInternetSales[SalesAmount]), ALL (DimSalesTerritory[SalesTerritoryCountry]) )
![Page 9: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/9.jpg)
Ratios and PercentagesExcel sheet with ratios and percentages
![Page 10: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/10.jpg)
BandingHow to handle analysis by discretization
![Page 11: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/11.jpg)
Analysis of product sell price
Product price changes over time, due toDiscountsPrice variations
Price is a continuous dimensionLeading to a very high fragmentationClassical solution: BANDING
From 0 to 100 USDFrom 101 to 500…
Very common pattern, even with SSAS
![Page 12: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/12.jpg)
Banding in PowerPivot: the quick and dirty solution= IF ( FactResellerSales[DiscountedPrice] <= 5, "01 LOW", IF ( FactResellerSales[DiscountedPrice] <=30, "02 MEDIUM", IF ( FactResellerSales[DiscountedPrice] <=100, "03 MEDIUM", IF ( FactResellerSales[DiscountedPrice] <= 500, "04 HIGH", "05 VERY HIGH"))))
Even if this works… a better data modelwould be welcome!
![Page 13: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/13.jpg)
Banding: a data driven model
SELECT P.BandName, SUM (S.ExtendedAmount)FROM dbo.FactResellerSales S JOIN PriceBands P ON S.UnitPrice BETWEEN P.FromPrice AND P.ToPriceGROUP BY P.BandName
BandName FromPrice ToPrice
VERY LOW 0 5
LOW 5 30
MEDIUM 30 100
HIGH 100 500
VERY HIGH 500 9999
![Page 14: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/14.jpg)
Banding data model with PowerPivot
We can leverage BAND Expansion with a different data model
SELECT P.BandName, SUM (S.ExtendedAmount)FROM dbo.FactResellerSales S JOIN PriceBands P ON S.UnitPrice = P.PriceGROUP BY P.BandName
Price BandName
1 VERY LOW
2 VERY LOW
3 VERY LOW
4 VERY LOW
5 VERY LOW
6 LOW
7 LOW
… …
![Page 15: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/15.jpg)
PowerPivot first solution: Band Expansion
PowerPivot has no BETWEEN… Thus we need Band ExpansionWe need…
A configuration sheet with band configurationScript to expand the configuration tableCreate a new linked tableConvert prices into integer valuesSetup the relationship
Very simple solution, probably the first one
![Page 16: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/16.jpg)
Band ExpansionBand Expansion, first trial
![Page 17: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/17.jpg)
Banding with DAX
We can leverage DAX to implement BETWEENNo need to perform table expansionUsage of FILTER to find the correct bandUsage of MAXX to convert a table into a value
BandName=MAXX ( FILTER ( PriceBands, FactResellerSales[DiscountedPrice] >= PriceBands[MinPrice] && FactResellerSales[DiscountedPrice] < PriceBands[MaxPrice] ), [PriceBand])
![Page 18: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/18.jpg)
MAXX does not work with strings…
MAXX works only with dates and numbers, no strings!Compatibility with Excel???
Add a new numeric codeUse MAXX to retrieve the numeric codeCreate a calculated column with the codeSet relationship on the code to find the band name
Tricky… yet it works fine and does not need VB scripts
![Page 19: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/19.jpg)
Banding with DAXFirst DAX solution
![Page 20: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/20.jpg)
Banding with CALCULATEThe key is CALCULATEChange the filter contextWorks with any expressionLeverages CALCULATE, VALUES and FILTER together
= CALCULATE( VALUES (PriceBands[PriceBand]), FILTER ( PriceBands, FactResellerSales[DiscountedPrice] >= PriceBands[MinPrice] && FactResellerSales[DiscountedPrice] < PriceBands[MaxPrice] ))
![Page 21: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/21.jpg)
SimulationWhat if we want to choose a new courier?
![Page 22: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/22.jpg)
The background
We have some courier proposalsParameters are
WeightDestination
Result is «Freight»We need to choose the best oneWe carry on a simulation based on the past shipmentsTwo problems
Determine the final weight of a shipmentCreate a good simulation environment
![Page 23: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/23.jpg)
Analysis of the dataLet us take a brief tour on the source data
![Page 24: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/24.jpg)
Compute the shipment weight
For each shipmentSum up the detail rowsUsing a standard many to one relationshipAnd the function RELATEDTABLE
= SUMX(RELATEDTABLE(OrderDetails),OrderDetails[TotalWeight])
![Page 25: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/25.jpg)
Freight for each courier
For each courierNew calculated columnLeverage of FILTER to find the right freightAnd of MAXX to convert a table into a scalar value(yes, it works with numbers! )
=MAXX( FILTER( 'Couriers', [Country] = 'Orders'[Country] && [MinWeight] <= 'Orders'[Weight] &&'Orders'[Weight] < [MaxWeight] && [Courier] = "SpeedyMail"), 'Couriers'[Freight])
![Page 26: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/26.jpg)
Using CALCULATE we get a more elegant solution
Using CALCULATEIf configuration sheet contains duplicates We get an errorCleaner solution, yet more complicated to understand
=CALCULATE( VALUES( 'Couriers'[Freight] ), FILTER( 'Couriers', [Country] = 'Orders'[Country] && [MinWeight] <= 'Orders'[Weight] &&'Orders'[Weight] < [MaxWeight] && [Courier] = "Blu Express") )
![Page 27: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/27.jpg)
SimulationFirst solution to the simulation pattern
![Page 28: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/28.jpg)
What if we have many couriers?
One calculated column for each courierMany columnsData model needs to be updated based on dataSoon we will introduce errors
Let us create a new solutionNew data modelBased on many to many relationship
ProblemsPowerPivot does not handle many to many relationshipsLess intuitive, yet very powerful
![Page 29: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/29.jpg)
Data model with Many to ManyBridge table
With the calculation parametersCountryWeight
Two relationshipsWith OrdersWith PriceList
ProblemsPowerPivot does not handle many to many relationshipsRelationship based on two columnsNeed to create the bridgeAnd to expand the configuration
![Page 30: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/30.jpg)
Bridge creation and expansion
Similar to the banding solutionEasily solved with some VbScript codeNo support in DAX or PowerPivot for this
![Page 31: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/31.jpg)
Relationship with two columns
PowerPivot handles relationships based on one column onlyEven if we live in 2010…And the relational model is 41 years old
SolutionCreate a new calculated column to hold the relationshipOn all tables.
![Page 32: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/32.jpg)
The DAX FormulaFar from being easyUses evaluation contexts:
Filter ContextRow Context
Uses CALCULATE to transform a ROW Context into a FILTER Context
=SUMX( Orders, CALCULATE ( IF( COUNT (PriceList[Freight]) = 1, VALUES (PriceList[Freight]), BLANK () ) ) )
![Page 33: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/33.jpg)
Simulation with many to manySolution of the simulation pattern with Many To Many relationships
![Page 34: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/34.jpg)
Semi Additive MeasuresHow to handle semi additive measures with PowerPivot
![Page 35: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/35.jpg)
Semi Additive Measure - DefinitionAdditive Measure
Aggregates with SUM over all dimensionsNon Additive Measure
Aggregates with different function over all dimensionsExample: average of the sale price
Semi Additive MeasureAggregates with SUM over some dimensionsAggregates with different function over other dimensionsTime is the standard exception for aggregationsExamples
Warehouse stockingCurrent account balance
![Page 36: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/36.jpg)
Example: current account balance
Month level correctQuarter level wrongYear level wrong
![Page 37: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/37.jpg)
Non additive measures
Change the aggregation functionDirectly inside PowerPivotWe can do it
With the user interfaceDefining a new measure
We cannot model the aggregation function inside the database
![Page 38: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/38.jpg)
Semi additive measuresAggregation function depend on the slicerIn the example
We should aggregate for LastChild over timeBut we should use SUM for the other dimensions
![Page 39: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/39.jpg)
Semi Additive Measures: Data ModelWe need to define a time dimension
It is not required by defaultEven if attribute consolidation comes from its adoptionIn this situation it is mandatory
New measure:CALCULATE: to set the filterLASTDATE: to find the last child
LastBalance = CALCULATE ( SUM(Balances[Balance]), LASTDATE(Date[Date]))
![Page 40: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/40.jpg)
Semi Additive MeasuresExcel sheet implementing semi additive measures
![Page 41: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/41.jpg)
Dynamic SetsHere we discover the underlying SSAS cube in PowerPivot.
![Page 42: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/42.jpg)
What is a set
Handled by ExcelStatic Set
Set of tuples (i.e. filter contexts)Uses standard MDX code or User InterfaceUser interface… works, but it could have been more user friendly
Dynamic SetNeed to be written with MDXAnd doing it…You will discover the SSAS cube inside PowerPivot
![Page 43: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/43.jpg)
Dynamic SetsExcel sheet working with static and dynamic sets
![Page 44: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/44.jpg)
LinksPowerPivothttp://www.powerpivot.com
DAX Introductionhttp://blogs.msdn.com/powerpivot/archive/2010/04/05/dax-data-analysis-expressions-measures-in-powerpivot.aspx
Marco Russo’s Bloghttp://www.sqlblog.com/Blogs/marco_russo/default.aspx
![Page 45: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/45.jpg)
Resources
www.microsoft.com/teched
Sessions On-Demand & Community Microsoft Certification & Training Resources
Resources for IT Professionals Resources for Developers
www.microsoft.com/learning
http://microsoft.com/technet http://microsoft.com/msdn
Learning
![Page 46: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/46.jpg)
Related Content
BIU302 – Enriching Microsoft PowerPivot for Microsoft Excel Applications Using DAX
BIU05-INT – DAX Patterns in PowerPivot
BIU02-HOL – Defining DAX Calculations with MS PowerPivot for MS Excel 2010
Product Demo Stations
![Page 47: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/47.jpg)
Complete an evaluation on CommNet and enter to win!
![Page 48: = IF ( FactResellerSales[DiscountedPrice]](https://reader035.vdocuments.net/reader035/viewer/2022062713/56649f4c5503460f94c6cf6e/html5/thumbnails/48.jpg)
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to
be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.