Bachelors Program in Business Analytics
Data Visualization with Power BI & Tableau
•
Bachelor
Data Modeling for Visual Analytics
Introduction
A visualization is only as reliable as the model beneath it. A polished dashboard can still produce misleading results when transactions are duplicated, relationships are ambiguous, dates are incomplete, or measures are calculated at the wrong level of detail. Data modeling is therefore not merely a technical preparation step; it is the design of a controlled analytical representation of an organization.
In Power BI and Tableau, a model connects business events to descriptive context. It determines how filters travel, how measures aggregate, how users navigate from summary to detail, and whether two analysts obtain the same answer from the same data. A well-designed model improves performance, interpretability, governance, and trust.
This chapter develops the foundations of visual-analytics modeling: facts, dimensions, keys, grain, relationships, cardinality, star schemas, hierarchies, date tables, semantic layers, and connection modes. It also examines common modeling failures and applies the concepts to an illustrative retail case.
Learning Objectives
By the end of this chapter, you should be able to:
distinguish fact tables from dimension tables;
define and document the grain of a table;
select appropriate primary, foreign, surrogate, and business keys;
explain relationship cardinality and filter direction;
design a basic star schema for Power BI or Tableau;
construct useful hierarchies and a complete date table;
compare import, extract, live-connection, and DirectQuery approaches;
evaluate a semantic model for accuracy, performance, usability, and governance.
1. The Analytical Model as a Representation of Reality
Operational databases are designed to record transactions efficiently. Analytical models are designed to answer questions consistently. These purposes differ. An order-entry system may separate customers, addresses, products, payments, and shipments across many normalized tables. A dashboard user, however, may need to ask: “What was net revenue by product category, region, and month?”
A model translates operational structures into analytical structures. It identifies:
Business processes—such as sales, inventory, service calls, or web visits.
Events or measurements—such as quantity sold, cost, discount, and revenue.
Descriptive context—such as product, customer, store, employee, and date.
Valid analytical paths—the relationships through which filters and aggregations operate.
The model should reflect business meaning rather than merely reproduce source-system tables. A column named Amount is not self-explanatory: it may represent gross sales, tax-inclusive sales, a payment, or a local-currency value. Modeling includes defining such meanings and recording assumptions.
2. Facts, Dimensions, and Grain
Fact tables
A fact table records measurable business events or periodic states. Typical columns include foreign keys and numeric measures:
Sales fact: order date, product key, customer key, store key, quantity, sales amount, discount, cost.
Inventory snapshot: date key, product key, warehouse key, units on hand.
Service fact: ticket key, opened date, resolved date, agent key, resolution minutes.
Facts may be additive, semi-additive, or non-additive. Revenue and quantity are usually additive across products, customers, and time. Account balance is generally additive across accounts but not across time; adding daily balances produces a meaningless total. Ratios, percentages, and unit prices should normally be recalculated from their component values rather than summed.
Dimension tables
A dimension supplies descriptive attributes used to group, filter, and label facts. Product, customer, date, store, salesperson, and promotion are common dimensions. A product dimension may contain product name, brand, category, package size, and current status.
Dimensions should provide stable, understandable attributes. They may contain history. For example, when a customer moves from one region to another, an organization must decide whether historical sales should remain associated with the former region. This is a slowly changing dimension issue. A type 1 approach overwrites the old value; a type 2 approach creates a new dimension record with effective dates and preserves history.
Grain: the most important modeling decision
The grain states exactly what one row represents. Examples include:
one row per order line;
one row per product per warehouse per day;
one row per customer per month;
one row per website session.
Every measure and relationship must be interpreted at that grain. If a sales table contains one row per order line, order-level shipping cost must not be repeated on every line and then summed. Doing so duplicates the cost.
A reliable modeling practice is to write a grain statement before building relationships: “Each row in FactSales represents one product line on one customer order.” The statement should be tested against source data and documented in the model.
Additivity and aggregation
For a measure such as revenue, the total is commonly calculated as:
Revenue = ∑ᵢ Revenueᵢ
Here, Revenuei is the revenue associated with fact row i. This summation is valid only when rows represent non-overlapping revenue events and revenue is recorded at a consistent currency and grain. If a table contains duplicate events or repeated header values, the formula is mathematically correct but analytically wrong because its input rows are wrong.
A safer ratio is often:
Average Unit Price = (∑ᵢ SalesAmountᵢ) ÷ (∑ᵢ Quantityᵢ)
The variables are sales amount and quantity for the selected rows. This is preferable to averaging row-level unit prices when transactions have different quantities. It assumes quantities are comparable and nonzero.
3. Keys and Data Integrity
A primary key uniquely identifies a row in a table. A foreign key stores a value that refers to a key in another table. In a star schema, a fact table normally contains foreign keys to dimensions, while a dimension contains its own primary key.
A business key originates in an operational system, such as a product code or customer number. A surrogate key is an artificial identifier, often an integer, generated for analytical purposes. Surrogate keys are useful when business identifiers change, differ between source systems, or must distinguish historical versions of a dimension member.
Key quality requires:
uniqueness on the referenced dimension side;
no unexplained nulls in fact foreign keys;
matching data types and formats;
a strategy for unknown or missing members;
reconciliation of unmatched keys.
An “Unknown” dimension row, often assigned a controlled key such as 0 or −1, is preferable to silently dropping facts. The exact value is a design convention, not a universal requirement.
4. Relationships, Cardinality, and Filter Propagation
A relationship specifies how rows in two tables correspond. Cardinality describes the number of matching rows on each side:
Relationship
Meaning
Typical example
One-to-one
One row matches one row
Employee and employee profile
One-to-many
One row matches many rows
Product to sales lines
Many-to-one
Many rows match one row
Sales lines to product
Many-to-many
Multiple rows match multiple rows
Students and courses
The normal star-schema pattern is one dimension to many fact rows. The dimension key must be unique; the fact may contain the same foreign key repeatedly.
Filter direction determines how selections propagate. Single-direction filtering from dimension to fact is usually easier to reason about and reduces ambiguity. Bidirectional filtering may be justified in carefully designed scenarios, but it can create multiple filter paths, unexpected results, or performance problems.
A model can contain active and inactive relationships. For example, a sales fact may have both OrderDate and ShipDate. One date relationship may be active by default, while the other is used only for a specific measure or view. In Power BI, measures can activate an inactive relationship with appropriate DAX; in Tableau, date roles and calculated fields can provide analogous analytical behavior. The key principle is to make date meaning explicit.
Many-to-many relationships
Many-to-many relationships require special care. A direct many-to-many connection can produce ambiguous filter paths or double counting. A bridge table is often clearer. For example, a customer may belong to several segments and a segment may contain many customers. A bridge table containing CustomerKey and SegmentKey represents membership. Measures must then be tested for the intended meaning: membership-based totals may legitimately allocate one customer to multiple segments, while customer counts across segments may not sum to the distinct total.
Star schema with dimensions surrounding a sales fact table
Figure: Star schema with dimensions surrounding a sales fact table
Figure: A conventional star schema in which descriptive dimensions filter a central sales fact table.
5. Star Schemas and Semantic Layers
A star schema places a fact table at the center and dimensions around it. It is generally preferable for visual analytics because it provides clear filter paths, predictable aggregation, and a user-friendly vocabulary. A snowflake schema normalizes dimensions into additional related tables, reducing some redundancy but increasing joins and conceptual complexity. Snowflaking can be appropriate where dimensions are very large or shared structures must be managed centrally, but unnecessary normalization often makes self-service analysis harder.
A semantic layer is the governed business-facing layer between raw data and reports. It may include:
standardized measures such as Net Sales and Gross Margin;
business definitions and units;
friendly names and folders;
certified dimensions and hierarchies;
row-level security;
data-quality indicators;
hidden technical columns;
documentation and ownership.
Power BI semantic models contain tables, relationships, measures, calculation logic, roles, and metadata. Tableau commonly expresses semantic behavior through published data sources, relationships, logical tables, calculations, and certified sources. The technologies differ, but the modeling objective is shared: users should analyze governed concepts rather than reconstruct them independently in every workbook.
A measure such as gross margin might be defined as:
Gross Margin = Net Sales − Cost of Goods Sold
The units of all terms must match, usually the same currency and reporting period. A margin percentage is:
Gross Margin % = (Net Sales − Cost of Goods Sold) ÷ Net Sales × 100%
This requires nonzero net sales and consistent treatment of returns, taxes, discounts, and currency conversion. It should normally be calculated from aggregated sales and cost, not as an unweighted average of row-level percentages.
6. Hierarchies and Date Tables
A hierarchy provides an intentional path from a broad level to a more detailed level. Examples include:
Geography: Country → State or Province → City → Store;
Product: Department → Category → Subcategory → Product;
Time: Year → Quarter → Month → Date.
A hierarchy is not simply a set of columns. Its levels must have a meaningful parent-child or drill path. For example, sorting month names alphabetically produces an invalid analytical order; a numeric month-of-year column should control sorting.
A robust date dimension contains one row for every date in the analysis range and attributes such as date, year, quarter, month number, month name, week, fiscal period, weekday, holiday flag, and working-day flag. It should be independent of whether a particular date has sales. A continuous date table enables correct time filtering, comparisons, and periods with zero activity.
A date key may be an actual date or an integer such as YYYYMMDD. The chosen design must be consistent and documented. Fiscal calendars require explicit fiscal-year and fiscal-period logic rather than assuming that January begins the financial year.
When a fact has multiple date meanings, role-playing dimensions can be used conceptually: Order Date, Ship Date, and Delivery Date each represent a role of the date dimension. The model must prevent users from confusing the default date context with an alternative date context.
7. Connection and Storage Approaches
Power BI and Tableau provide several ways to access data. Names and capabilities vary by product version, but the conceptual distinctions are stable.
Approach
Where data is processed
Strengths
Risks or trade-offs
Import / in-memory model
Data is loaded into the analytical engine
Fast interaction, rich calculations, compression
Refresh schedules, memory limits, data latency
Extract
A prepared Tableau extract stores a queryable copy
Good performance, offline or scheduled use
Requires refresh and extract governance
Live connection
Queries remain directed to the source or published model
Central control, fresher data
Source performance and feature constraints
DirectQuery
Power BI sends queries to the source at interaction time
Import and extracts are not identical product features, but both represent a stored analytical copy. They usually offer fast visual interaction because the tool can optimize repeated queries locally. Refresh design must address credentials, incremental loading, failure monitoring, and data freshness expectations.
Live and DirectQuery approaches preserve a closer connection to source data but make dashboard performance dependent on source indexing, network latency, concurrency, and query folding or translation. They are not automatically more accurate; a badly defined source query can still produce incorrect results.
The choice should be based on data volume, latency requirements, concurrency, source-system capacity, security, calculation needs, and operational skills. “Real time” is meaningful only when the business specifies an acceptable freshness interval and the complete pipeline can meet it.
8. Worked Example: Diagnosing a Granularity Error
Suppose an order header has shipping cost of $12, and the order contains three product lines. A fact table is built at order-line grain, but the $12 shipping cost is copied into all three rows. A simple sum reports:
Reported Shipping = 12 + 12 + 12 = $36
The correct order-level shipping cost is $12. The error is not caused by Power BI or Tableau; it is caused by placing an order-level measure into a line-level table without an allocation rule.
Three valid solutions are possible:
Keep shipping in an order-grain fact and relate it through an appropriate order dimension or aggregate.
Allocate shipping across lines using a documented rule, such as proportional sales value.
Store shipping only once and create a measure that aggregates it at order grain.
If proportional allocation is selected, and line sales values are $20, $30, and $50, the allocation for line i is:
AllocatedShippingᵢ = 12 × (LineSalesᵢ ÷ 100)
The allocated values are $2.40, $3.60, and $6.00, which sum to $12. This method assumes sales value is an acceptable allocation basis. It is not universally correct; logistics policy or accounting standards may require another basis.
9. Illustrative Case: Northstar Retail
Background and problem
Northstar Retail operates 120 stores and an online channel. Executives report that regional revenue differs between the finance dashboard and the sales dashboard. Analysts also report slow performance and inconsistent definitions of “active customer.”
Investigation finds that the sales dashboard joins order headers directly to product lines, repeating header-level tax and shipping. The product table contains duplicate product codes because two source systems use overlapping identifiers. Dates are stored only on transaction rows, so months with no sales disappear from trend charts. Finally, analysts calculate net sales independently, with different treatments of returns.
Analysis and approach
The team first documents business processes and grains:
FactSales: one row per order line;
FactOrderCharges: one row per order;
FactReturns: one row per returned order line;
DimProduct: one row per product version;
DimCustomer: one row per customer version;
DimStore: one row per store;
DimDate: one row per calendar date.
Surrogate product keys distinguish products from the two source systems and preserve product-category history. A conformed date dimension is connected to each relevant fact. The team creates governed measures for gross sales, returns, net sales, and gross margin. Order-level shipping is kept separate from line-level sales rather than duplicated.
The semantic layer defines active customer as a customer with at least one completed purchase in the selected period, excluding cancelled orders. It also documents whether sales are tax-inclusive and how exchange rates are applied. Row-level security restricts regional managers to their authorized stores.
The initial model uses import and scheduled incremental refresh because executive analysis does not require second-by-second data. Store operations receive a separate near-current operational view. Model validation compares totals against finance-controlled reports at daily, store, and product levels.
Outcome
Revenue differences are traced to duplicated charges and inconsistent return handling. After remediation, the dashboards reconcile within defined tolerances, monthly charts show zero-activity periods correctly, and common product-category analysis becomes faster. More importantly, analysts can explain why a number is produced.
Learning points
The case demonstrates that performance problems and trust problems often have the same root: an unclear model. Grain documentation, conformed dimensions, controlled measures, and reconciliation are more valuable than adding more charts. Separating operational freshness requirements from executive analytical requirements also prevents an unnecessarily expensive architecture.
10. Validation, Governance, and Professional Practice
Model validation should be systematic. Useful checks include:
row counts before and after transformations;
uniqueness of dimension keys;
unmatched foreign keys;
null and unknown-member rates;
totals reconciled to trusted source reports;
duplicate detection at declared grain;
tests for date completeness;
checks that measures behave correctly when filtered by each dimension;
performance tests under realistic concurrency.
A model should also have an owner, refresh information, source lineage, definitions, sensitivity classification, and change history. Access controls must be applied at the model or source layer where possible. Row-level security is not a substitute for protecting the underlying data source, and exporting data can undermine otherwise sound controls.
Ethically, analysts must avoid presenting false precision. A dashboard should identify missing data, delayed refreshes, suppressed populations, and known exclusions. Customer, employee, health, or financial data may be subject to privacy law and organizational policy. Least-privilege access, masking, retention controls, and audit logs are practical governance requirements.
AI-assisted modeling can suggest relationships, classifications, or calculated expressions, but suggestions require human verification. AI may infer an incorrect key, overlook grain, expose sensitive fields, or encode an unjustified business definition. Model documentation and tests remain necessary regardless of how the model was created.
11. A Practical Design Workflow
A disciplined workflow is:
Identify the analytical questions and business processes.
Declare the grain of every fact and important aggregate.
Classify facts, dimensions, measures, and attributes.
Profile keys, nulls, duplicates, dates, units, and currencies.
Build conformed dimensions, especially Date and shared entities.
Prefer a clear star schema and single-direction dimension-to-fact paths.
Create governed measures and hide technical implementation fields.
Add hierarchies only when their drill paths are valid.
Select import, extract, live, DirectQuery, or composite storage based on requirements.
Validate totals, filter behavior, security, refresh, and performance.
Publish definitions, lineage, ownership, and known limitations.
Monitor usage and revise the model through controlled change management.
Chapter Summary
Data modeling provides the logical foundation for trustworthy visual analytics. Fact tables record events or states, while dimensions provide descriptive context. The declared grain determines what each row means and controls whether measures can be safely aggregated. Primary, foreign, business, and surrogate keys support identity and historical integrity.
Star schemas usually provide clear and efficient analytical paths. Cardinality, filter direction, active relationships, and bridge tables must be designed deliberately, especially for many-to-many situations. Hierarchies and complete date tables make navigation and time analysis meaningful. A semantic layer turns technical structures into governed business concepts through standard measures, metadata, security, and documentation.
Import, extracts, live connections, and DirectQuery represent different balances of speed, freshness, source workload, scale, and capability. No approach is universally best. Professional modelers select an architecture from requirements, validate it against trusted totals, and communicate assumptions and limitations. Reliable dashboards are therefore the outcome of reliable models, not merely attractive visual design.
Key Terms
Analytical model: A structured representation of data designed for analysis and reporting.
Business key: An identifier originating in an operational business system.
Cardinality: The number of matching rows between related tables.
Conformed dimension: A shared dimension used consistently across multiple fact tables or processes.
Dimension table: A table containing descriptive attributes used to filter and group facts.
DirectQuery: A Power BI approach that queries the source system at interaction time rather than importing all data.
Extract: A stored Tableau data copy optimized for analytical querying.
Fact table: A table recording measurable events or periodic states.
Foreign key: A field referring to a key in another table.
Grain: The precise meaning represented by one row of a table.
Hierarchy: An ordered set of analytical levels supporting drill-down.
Import: Loading data into an in-memory analytical model.
Many-to-many relationship: A relationship in which multiple rows on each side can match.
Primary key: A field or combination of fields that uniquely identifies a row.
Role-playing date: A date dimension used in different roles, such as order date and ship date.
Semantic layer: A governed business-facing layer containing definitions, calculations, relationships, and security.
Slowly changing dimension: A dimension whose attribute values change over time and require a history policy.
Star schema: A central fact table connected directly to descriptive dimensions.
Surrogate key: An analytically generated identifier used independently of a business identifier.
Bridge table: An intermediary table used to represent complex or many-to-many relationships.
Review Questions
Short Answer Questions
What is the difference between a fact table and a dimension table?
Why must the grain of a fact table be documented before measures are created?
Define primary key, foreign key, and surrogate key.
What is the usual filter direction in a star schema, and why is it preferred?
State one important difference between Import and DirectQuery.
Long Answer Questions
Explain how grain and additivity affect the reliability of revenue and inventory measures.
Compare star and snowflake schemas in terms of usability, performance, and governance.
Describe how a complete date table supports time-series analysis and fiscal reporting.
Explain the purpose of a semantic layer in Power BI or Tableau.
Discuss the factors that should guide the choice between import, extract, live, and DirectQuery approaches.
Analytical / Application Questions
A sales fact is at order-line grain, but order-level freight is repeated on every line. Diagnose the problem and propose two valid remedies.
Design a star schema for a university bookstore that analyzes sales by date, student type, product, campus, and sales channel. State the grain of the sales fact and identify at least five dimensions.
A company has OrderDate, ShipDate, and DeliveryDate in one fact table. Explain how you would model and expose these roles so that users do not confuse the default date context.
Multiple Choice Questions with Answers
Question 1
Which statement best defines the grain of a fact table?
A. The number of columns in the table
B. The precise business meaning of one row
C. The storage format used by the table
D. The number of dimensions connected to the table
Correct Answer: B. The precise business meaning of one row
Question 2
In a conventional star schema, which relationship is most typical?
A. Product dimension one-to-many Sales fact
B. Sales fact one-to-one Date dimension
C. Product dimension many-to-many Sales fact in every case
D. Date dimension many-to-many Customer dimension
Correct Answer: A. Product dimension one-to-many Sales fact
Question 3
Why can summing an order-level shipping cost in an order-line fact produce an incorrect result?
A. The currency is always converted twice
B. The date dimension removes shipping rows
C. The cost is repeated for each line of the same order
D. Dimensions cannot contain numeric values
Correct Answer: C. The cost is repeated for each line of the same order
Question 4
Which key is usually generated for analytical purposes and can preserve history when a business identifier changes?
A. Foreign key
B. Surrogate key
C. Display key
D. Format key
Correct Answer: B. Surrogate key
Question 5
What is generally the safest default filter direction in a star schema?
A. Fact to every dimension
B. Bidirectional across every relationship
C. Dimension to fact
D. Random direction selected by the visualization
Correct Answer: C. Dimension to fact
Question 6
Which characteristic is essential for a robust date dimension?
A. It contains only dates on which transactions occurred
B. It contains a continuous range of relevant dates
C. It stores month names without month numbers
D. It must be rebuilt for every visualization
Correct Answer: B. It contains a continuous range of relevant dates
Question 7
If sales are $80,000 and cost of goods sold is $50,000, what is gross margin percentage?
A. 30%
B. 37.5%
C. 62.5%
D. 160%
Correct Answer: B. 37.5%
Question 8
Which approach normally stores data in an analytical engine for fast interactive querying?
A. Import
B. DirectQuery only
C. Unindexed live connection
D. Manual spreadsheet linking
Correct Answer: A. Import
Question 9
What is a common purpose of a bridge table?
A. To remove all dimension attributes
B. To represent a complex or many-to-many relationship
C. To replace every primary key
D. To guarantee real-time refresh
Correct Answer: B. To represent a complex or many-to-many relationship
Question 10
Which statement about AI-assisted model suggestions is most appropriate?
A. They eliminate the need to test relationships
B. They are always correct when column names match
C. They should be reviewed against grain, meaning, security, and data quality
D. They automatically establish legal compliance
Correct Answer: C. They should be reviewed against grain, meaning, security, and data quality
Data Visualization with Power BI & Tableau
Chapter 5
of 14