- •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
a simple variation on the formulas you have seen so far, as shown in the following DAX code:
Click here to view code image
Sales2008AtBudgetGranularity := CALCULATE (
[Sales 2008], ALL ( Store ),
VALUES ( Store[CountryRegion] ), ALL ( Product ),
VALUES ( Product[Brand] )
)
AllocationFactor := DIVIDE ( [Sales 2008], [Sales200
Allocated Budget := SUM ( Budget[Budget] ) * [Alloca
The core of the previous formulas is Sales2008AtBudgetGranularity, which computes the sales amount after removing filters from Store and Product, apart from the columns that define the granularity at the Budget level. The remaining two measures are a simple division and a multiplication. Use the numbers shown in Figure 9-14 to produce the desired result.
The technique of reallocating at the higher granularity is very interesting, and it gives the user the feeling that numbers are present at a higher granularity than they really are. However, if you plan to use this technique, you should clearly explain how the numbers are computed to the stakeholders. At the very end, the numbers are derived from a calculation, and they are not what is entered when the budget is created.
Conclusions
Granularity is one topic you need to understand to build any data model, and has been discussed in many chapters throughout this book. This chapter went a step further to analyze some options that are available when granularity cannot be fixed because data is already stored at the right level.
The most important topics covered in this chapter are as follows:
Granularity is defined by the level at which the dimensions are linked to the fact table.
Different fact tables can present different levels of granularity because of
the nature of their data. Usually, granularity issues are errors in the model. However, there are scenarios where fact tables are stored at the correct granularity, which is different from table to table.
When multiple fact tables have different granularity, you must build a model that lets you slice all the tables using one dimension. You can do so either by creating a special model at the correct granularity or by moving the filter through DAX code or bidirectional relationships.
You must be aware of granularity differences among your facts and handle them properly. You have multiple options: ignoring the problem, hiding the data when granularity becomes too high, or reallocating the values using some allocation factor.