- •Contents at a glance
- •Contents
- •Introduction
- •Who this book is for
- •Assumptions about you
- •Organization of this book
- •Conventions
- •About the companion content
- •Acknowledgments
- •Errata and book support
- •We want to hear from you
- •Stay in touch
- •Chapter 1. Introduction to data modeling
- •Working with a single table
- •Introducing the data model
- •Introducing star schemas
- •Understanding the importance of naming objects
- •Conclusions
- •Chapter 2. Using header/detail tables
- •Introducing header/detail
- •Aggregating values from the header
- •Flattening header/detail
- •Conclusions
- •Chapter 3. Using multiple fact tables
- •Using denormalized fact tables
- •Filtering across dimensions
- •Understanding model ambiguity
- •Using orders and invoices
- •Calculating the total invoiced for the customer
- •Calculating the number of invoices that include the given order of the given customer
- •Calculating the amount of the order, if invoiced
- •Conclusions
- •Chapter 4. Working with date and time
- •Creating a date dimension
- •Understanding automatic time dimensions
- •Automatic time grouping in Excel
- •Automatic time grouping in Power BI Desktop
- •Using multiple date dimensions
- •Handling date and time
- •Time-intelligence calculations
- •Handling fiscal calendars
- •Computing with working days
- •Working days in a single country or region
- •Working with multiple countries or regions
- •Handling special periods of the year
- •Using non-overlapping periods
- •Periods relative to today
- •Using overlapping periods
- •Working with weekly calendars
- •Conclusions
- •Chapter 5. Tracking historical attributes
- •Introducing slowly changing dimensions
- •Using slowly changing dimensions
- •Loading slowly changing dimensions
- •Fixing granularity in the dimension
- •Fixing granularity in the fact table
- •Rapidly changing dimensions
- •Choosing the right modeling technique
- •Conclusions
- •Chapter 6. Using snapshots
- •Using data that you cannot aggregate over time
- •Aggregating snapshots
- •Understanding derived snapshots
- •Understanding the transition matrix
- •Conclusions
- •Chapter 7. Analyzing date and time intervals
- •Introduction to temporal data
- •Aggregating with simple intervals
- •Intervals crossing dates
- •Modeling working shifts and time shifting
- •Analyzing active events
- •Mixing different durations
- •Conclusions
- •Chapter 8. Many-to-many relationships
- •Introducing many-to-many relationships
- •Understanding the bidirectional pattern
- •Understanding non-additivity
- •Cascading many-to-many
- •Temporal many-to-many
- •Reallocating factors and percentages
- •Materializing many-to-many
- •Using the fact tables as a bridge
- •Performance considerations
- •Conclusions
- •Chapter 9. Working with different granularity
- •Introduction to granularity
- •Relationships at different granularity
- •Analyzing budget data
- •Using DAX code to move filters
- •Filtering through relationships
- •Hiding values at the wrong granularity
- •Allocating values at a higher granularity
- •Conclusions
- •Chapter 10. Segmentation data models
- •Computing multiple-column relationships
- •Computing static segmentation
- •Using dynamic segmentation
- •Understanding the power of calculated columns: ABC analysis
- •Conclusions
- •Chapter 11. Working with multiple currencies
- •Understanding different scenarios
- •Multiple source currencies, single reporting currency
- •Single source currency, multiple reporting currencies
- •Multiple source currencies, multiple reporting currencies
- •Conclusions
- •Appendix A. Data modeling 101
- •Tables
- •Data types
- •Relationships
- •Filtering and cross-filtering
- •Different types of models
- •Star schema
- •Snowflake schema
- •Models with bridge tables
- •Measures and additivity
- •Additive measures
- •Non-additive measures
- •Semi-additive measures
- •Index
- •Code Snippets
is not browsing below the granularity of Budget. The result is shown in Figure 9- 13, where Budget is correctly reported at the brand level, and is blanked at the color level.
FIGURE 9-13 This report blanks the value of Budget below the correct granularity.
Note
Whenever you have fact tables at different granularity, it is very important to recognize when a value should not be shown because of granularity issues. Otherwise, the report will always produce a number—and it is likely to be the wrong one.
Allocating values at a higher granularity
In the previous examples, you learned how to hide values when the user is browsing at a granularity that is no longer supported by the data model. This technique is useful to avoid showing a wrong number. For some specific scenarios, however, you can do more than this. You can compute the value at the higher granularity using an allocation factor. For example, suppose you do not
know the budget of blue products at a company called Adventure Works. (You only know the budget for the total of Adventure Works.) You can ascertain this by taking a percentage of the total budget, which you can compute on the fly. This percentage is the allocation factor.
A good allocation factor can be, for example, the percentage of sales of blue products against the totality of colors in the previous year. Rather than trying to describe it with words, it is much simpler to look at the final report shown in Figure 9-14.
FIGURE 9-14 The Allocated Budget column shows values at a higher granularity by computing them dynamically.
Let us examine Figure 9-14 in more detail. In previous figures, we used Sales 2009, whereas here we are showing Sales 2008. This is because we use Sales 2008 to compute the allocation factor, which is defined here as the amount of sales in 2008 of blue products divided by the amount of sales in 2008 at the Budget granularity.
You can see, for example, that blue products from Adventure Works made $8,603.64 in sales, which, divided by $93,587.00, results in 9.19% as the share of sales in 2008. The budget of blue products is not available in 2009, but you can compute it by multiplying the budget of Adventure Works products by the share in 2008, for an expected value of $6,168.64.
Computing the value is simple when you understand the granularity details. It is