Sub topic 16
Anti-patterns to avoid and how to fix them
This chapter assumes you have read the earlier chapters. You should know what grain, fact tables, dimension tables, keys, and one-to-many relationships are. You should also be comfortable with basic Power Query and DAX. Here we collect the mistakes that most often break a star schema, show how to spot each one, and show how to fix it.
How to approach a model review
Most modeling problems show up in one of three ways. Numbers are wrong, slicers behave oddly, or the model is large and slow. Each anti-pattern below lists its symptoms first, then the cause, then the fix.
A quick review checklist:
- Can you state the grain of every fact table in one sentence?
- Does every relationship run from a unique dimension key (the one side) to a fact foreign key (the many side)?
- Are all filters single-direction unless you can justify otherwise?
- Is there one date table, marked as a date table?
- Do numeric columns that users aggregate live in facts, and descriptive columns in dimensions?
Anti-pattern 1: one wide table
Symptoms. The model has a single table with dozens of columns. Customer, product, and date attributes repeat on every row. The file is large, and measures like distinct counts are slow.
Cause. The data was loaded as exported from a spreadsheet or a reporting query, and nobody split it.
Why it hurts. The VertiPaq engine stores each column separately and compresses it. Repeating a product name on millions of rows still costs memory for the dictionary and index. Slicers also have to scan the big table to list their values. Worse, you cannot show a product that had no sales, because the product only exists inside sales rows.
Fix. Split the table into one fact table and one dimension per business entity. In Power Query, the product dimension comes from selecting the product columns and removing duplicates:
let
Source = SalesFlat,
ProductColumns = Table.SelectColumns(Source, {"ProductID", "ProductName", "Subcategory", "Category"}),
DimProduct = Table.Distinct(ProductColumns, {"ProductID"})
in
DimProductDo the same for customers, stores, and any other entity. Then remove the descriptive columns from the original table so it keeps only keys and numbers. Keep ProductID in the fact table as the foreign key.
Anti-pattern 2: mixed or undefined grain
Symptoms. Totals are too high or too low. A measure works at the order level but double counts at the line level. Some rows in the fact table look like details and others like summaries.
Cause. One fact table holds rows at different levels. A common example is order-line rows plus an order-level freight charge repeated on each line. Summing the freight then multiplies it by the number of lines.
Fix. Pick one grain per fact table and write it down. Move order-level values into their own fact table at order grain, or allocate them to lines during load. The fact table from earlier chapters shows a clean grain: one row per order line, identified by OrderNumber and OrderLineNumber.
CREATE TABLE DimProduct (
ProductKey INT PRIMARY KEY,
ProductName VARCHAR(100) NOT NULL,
Subcategory VARCHAR(50),
Category VARCHAR(50)
);
CREATE TABLE FactSales (
OrderNumber VARCHAR(20) NOT NULL,
OrderLineNumber INT NOT NULL,
DateKey INT NOT NULL,
ProductKey INT NOT NULL REFERENCES DimProduct (ProductKey),
Quantity INT NOT NULL,
SalesAmount DECIMAL(18, 2) NOT NULL,
PRIMARY KEY (OrderNumber, OrderLineNumber)
);If two facts share dimensions but have different grains, such as sales and budget, keep them as separate fact tables and connect both to the shared dimensions.
Anti-pattern 3: unnecessary bidirectional filters
Symptoms. Slicers narrow each other in surprising ways. Report pages slow down after a relationship is changed. Power BI warns about ambiguous paths.
Cause. Someone set a relationship's cross-filter direction to Both to make a slicer on one dimension react to another. With several dimensions around a fact table, filters can travel from one dimension, through the fact table, into another dimension. That can create more than one path between two tables.
Fix. Set the direction back to single, from dimension to fact. If a slicer should only list values that have data, use one of these instead:
- Add a measure such as
Total Salesto the slicer's visual filter and filter it to "is not blank". - Use a measure with
CROSSFILTERorTREATASinsideCALCULATEfor the one calculation that needs reverse filtering.
Total Sales = SUM ( Sales[SalesAmount] )
Total Quantity = SUM ( Sales[Quantity] )Keep bidirectional filtering for the rare case you can explain, such as a bridge table in a many-to-many design. Even then, apply it to that one relationship only.
Anti-pattern 4: duplicate or blank keys on the one side
Symptoms. Power BI will not create a one-to-many relationship and offers many-to-many instead. Or a visual shows a "(Blank)" row with a large total.
Cause. The dimension key is not unique, often because the dimension was built without removing duplicates, or because the source has two rows for the same product with different attributes. A blank row appears when the fact table has keys that do not exist in the dimension. These are called orphan keys.
Fix.
- Make the dimension key unique. Use
Table.Distincton the key, or decide which version of a changed row to keep. - Find orphan keys by comparing the fact foreign key to the dimension key, for example with a merge using an anti join in Power Query.
- Add an "Unknown" row to the dimension and map missing keys to it during load, so totals still reconcile.
Do not accept a many-to-many relationship just to make the error go away. It hides the data quality problem and makes filters less predictable.
Anti-pattern 5: no proper date table, or several of them
Symptoms. Time intelligence functions return errors or wrong values. Each fact table has its own date column used directly in visuals. The model contains many hidden auto date/time tables.
Cause. Dates were left as columns on facts, and Power BI generated automatic date hierarchies for each one.
Fix. Build one date dimension with one row per day and no gaps, mark it as a date table, and relate every fact date column to it. Then turn off auto date/time in the options so hidden tables are not created.
Date =
ADDCOLUMNS (
CALENDAR ( DATE ( 2022, 1, 1 ), DATE ( 2025, 12, 31 ) ),
"DateKey", YEAR ( [Date] ) * 10000 + MONTH ( [Date] ) * 100 + DAY ( [Date] ),
"Year", YEAR ( [Date] ),
"Month Number", MONTH ( [Date] ),
"Month", FORMAT ( [Date], "MMM" )
)Sort the Month column by Month Number so months do not appear alphabetically.
Anti-pattern 6: copying the date table for each role
Symptoms. There are tables named OrderDate, ShipDate, and DueDate, each a copy of the same calendar. Changes must be repeated in all of them. Reports cannot compare roles easily.
Cause. The author did not know that one dimension can play several roles.
Fix. Keep one date table. Make one relationship active, usually order date, and leave the others inactive. Activate an inactive relationship inside a measure with USERELATIONSHIP:
Sales by Ship Date =
CALCULATE (
[Total Sales],
USERELATIONSHIP ( Sales[ShipDateKey], 'Date'[DateKey] )
)Use separate copies only when users must slice by two roles in the same visual at once, for example order year on rows and ship year on columns. In that case, name the copies clearly and generate them from the same source query.
Anti-pattern 7: over-normalized dimensions
Symptoms. A chain of small tables runs from the fact table: product, then subcategory, then category. Every slicer needs several relationships to resolve. The model view is hard to read.
Cause. The source database was normalized for transactions, and the structure was loaded as is.
Fix. Flatten the chain into one dimension that holds product, subcategory, and category columns. In Power Query, merge the tables and expand the needed columns. Snowflaking is acceptable when a shared sub-dimension serves several tables, but it should be a choice, not a default.
Anti-pattern 8: heavy columns that nobody uses
Symptoms. The file is large and refreshes slowly. Memory use is high compared with the row count.
Cause. High-cardinality columns such as GUIDs, timestamps with seconds, or long free-text comments are loaded into the fact table. Each distinct value takes space in the column dictionary.
Fix.
- Remove columns that no report, measure, or relationship uses.
- Split a datetime into a date key and a time-of-day value at a coarser precision, if the time is needed at all.
- Use integer surrogate keys for relationships instead of long text keys.
- Prefer measures over calculated columns when the value can be computed at query time.
Summary table
| Anti-pattern | Typical symptom | Fix |
|---|---|---|
| One wide table | Large file, no products without sales | Split into fact and dimensions |
| Mixed grain | Inflated totals | One grain per fact table |
| Bidirectional filters | Ambiguous paths, odd slicers | Single direction, targeted DAX |
| Duplicate or orphan keys | Many-to-many prompt, blank rows | Unique keys, Unknown member |
| Missing date table | Broken time intelligence | One marked date table |
| Date copies per role | Repeated maintenance | One table plus `USERELATIONSHIP` |
| Over-normalized dimensions | Long relationship chains | Flatten into one dimension |
| Heavy unused columns | Slow refresh, big file | Remove or reduce cardinality |
Exercise
A fact table has one row per order line and also a column named OrderFreight that repeats the whole order's freight on each line. A report that sums OrderFreight shows totals far above the real figure. Name the anti-pattern and give two ways to fix it.
Show answer
This is mixed grain. The freight value belongs to the order, not to the line, so summing it counts it once for every line. Fix it by moving freight into a separate fact table at order grain with a key to the shared dimensions, or by allocating the freight across the lines during load (for example in proportion to line amount) so the line values add up to the order freight.
Exercise
Your model has a relationship from Customer to Sales set to filter in both directions, and a slicer on Product now changes the list of customers in an unrelated visual. How do you restore predictable behavior, and how can you still make a customer slicer show only customers with sales?
Show answer
Set the relationship's cross-filter direction to single, from Customer to Sales. To limit the slicer to customers with sales, add Total Sales as a visual-level filter on the slicer with the condition "is not blank". Another option is to use CROSSFILTER or TREATAS inside a measure that needs the reverse filter.