24. Power Pivot and the Data Model
24.3 Diagram View and Relationships
Repair a report that repeats the grand total on every city row
Imagine you have just loaded Orders and Stores into the Excel Data Model. In the report you place City from Stores in Rows and Amount from Orders in Values. The sales total is the correct ₹2315. But each city may display that same amount, or Excel may prompt you to create a relationship. The calculation can add Orders perfectly while the city labels have no effect on which orders are included. A relationship establishes how to move from a selected lookup value to its matching fact records.
In this example each approved Stores row describes one store. Its StoreID identifies it. Each Orders row records one purchase and includes that store's identifier. A relationship lets a selection of Pune retain all approved Stores rows for Pune, then find the Orders records whose StoreID belongs to that selection. Orders need not contain a physically repeated City column. The relationship supplies the approved model filter path without copying one entire table into another.
- Choose the correct key, not just a familiar label. Match StoreID to StoreID. City is a grouping field and may repeat in the store list.
- Check uniqueness and coverage independently. The lookup key must be unique, and every expected fact key should resolve.
- Prove one known slice. The total sales amount can remain ₹2315 when categories are disconnected or a single city loses an order.
Use the original approved practice model
Open a copy of the twelve-order workbook from the Power Pivot setup lesson or rebuild those three exact original Tables. Confirm model counts of twelve Orders, four Stores and four Products. Use Amount as a numeric measure in rupees. The table below isolates the fields you need for the relationship. The original Order Date, CustomerID and Qty continue to exist in Orders, but the first relationship can be verified with these keys and values alone.
| OrderID | StoreID | ProductID | Amount |
|---|---|---|---|
| O-101 | BLK-PUN-01 | P01 | 128 |
| O-102 | BLK-NSK-01 | P02 | 180 |
| O-103 | AMN-NGP-01 | P03 | 195 |
| O-104 | BLK-PUN-01 | P04 | 220 |
| O-105 | AMN-SLP-01 | P02 | 90 |
| O-106 | BLK-PUN-01 | P01 | 192 |
| O-107 | BLK-PUN-01 | P02 | 270 |
| O-108 | BLK-NSK-01 | P04 | 220 |
| O-109 | AMN-NGP-01 | P01 | 160 |
| O-110 | AMN-SLP-01 | P03 | 260 |
| O-111 | BLK-PUN-01 | P03 | 130 |
| O-112 | BLK-NSK-01 | P02 | 270 |
| StoreID | City |
|---|---|
| BLK-PUN-01 | Pune |
| BLK-NSK-01 | Nashik |
| AMN-NGP-01 | Nagpur |
| AMN-SLP-01 | Solapur |
Write down what one row means in both tables before choosing a link. Stores has a unique record for BLK-PUN-01, and Orders contains five approved records using that store. Both can have a column named StoreID while fulfilling different roles. In a relational model, the unique store identifier can be described as its primary key. An Orders StoreID value referring to it is a foreign key. One store can match many order records. Orders do not need to repeat their own OrderID for the relationship to be one-to-many.
Create and inspect the relationship in Diagram View
Use supported Windows desktop Excel with Power Pivot. Open Power Pivot Manage, then switch from Data View to Diagram View using the appropriate control in your version. Microsoft documents creating relationships by opening the Create Relationship dialog from a table diagram, or connecting matching fields using the diagram as supported. Use the dialog variant below if dragging leaves the active fields or relationship direction unclear. You can also use Data Relationships in supported Excel versions.
- Identify the fact table Orders and its lookup table Stores. Confirm both actual model table names and their intended StoreID columns.
- Open Create Relationship. In the Excel dialog, select Orders as Table and Orders StoreID as the foreign column.
- Choose Stores as Related Table and Stores StoreID as the related unique column. Confirm the definition and check the diagram.
- Repeat with Orders ProductID as many-side field and Products ProductID as lookup key. Verify the two relationships use different entity types.
- Inspect the solid relationship lines and the indicated one and many sides. Diagram layout can arrange boxes in several ways. Changing their screen positions does not change how the keys relate.
A valid relationship does not copy lookup cells into the fact table. Use it to ask: when the PivotTable requests city Pune, what stores qualify? With the original stores, one key qualifies: BLK-PUN-01. Each of the five Orders rows with that key contributes its Amount, producing ₹940. Orders with another StoreID are outside that context. With no city filter in the grand total, all twelve original input rows contribute ₹2315.
Record related columns in the order “Lookup key filters matching fact field.” For the two model edges that is Stores StoreID to Orders StoreID, and Products ProductID to Orders ProductID. In a dialog the fact table might appear first because it asks for the foreign column, while you describe the filter by starting with the lookup. Keep the terms and their purpose clear. Do not infer the filter rules from only the left-right placement of a drawn line.
Build a model PivotTable that can expose the difference
Put Stores City in Rows and Orders Amount in Values using Sum, or use a simple explicit measure summing Orders Amount. Do not choose a specialized measure that intentionally removes City filters while testing the relationship. In a disconnected before-test, Excel may give a relationship warning, or the unrestricted value can repeat under each city heading. Once connected, the report should use the actual known groups below. Read the PivotTable field list and verify the row label is Stores City rather than an unrelated worksheet field or a copied model table.
| City | No effective city filter | With valid matching relationship | Orders rows after linking |
|---|---|---|---|
| Pune | 2315 | 940 | 5 |
| Nashik | 2315 | 670 | 3 |
| Nagpur | 2315 | 355 | 2 |
| Solapur | 2315 | 350 | 2 |
| Grand total | 2315 | 2315 | 12 |
Adding the four repeated amounts yourself would give ₹9260. The measure’s grand-total cell can still evaluate to ₹2315 because it recalculates in the grand-total context, which has all legitimate fact rows once. This apparent disagreement is useful evidence of the disconnected label problem. A visual is a query against the model with a specific set of grouping or filter fields. The result is not a simple list of numbers that Excel must add vertically.
Trace a Pune label into five correct fact rows
Start from a selected city
At the Pune row, Stores City supplies a Pune filter. Verify this is the actual dimension field in the report.
Retain approved store keys
Stores maps Pune to BLK-PUN-01 in this sample. In a wider model a city could legitimately select several unique store records.
Narrow the Orders rows
Orders O-101, O-104, O-106, O-107 and O-111 share that key. Confirm five valid facts and their approved amounts.
Verify the calculated slice
The five approved values sum to ₹940. Clearing the City filter brings back all twelve and ₹2315.
Check structure, key data and filter behavior separately
A unique lookup key and an accepted fact key are different checks
Identify duplicate StoreID values in Stores before creating a new relationship. With a real one-to-many design, a lookup key cannot be ambiguous. Have the source owner choose a valid resolution if the duplicates are conflicting. One can be a mistaken extract copy, an older record for the same store, or a separate entity using the same legacy identifier. Simply keeping the first row can attach the wrong city to an entire set of sales. Define the active lookup definition and key before correcting the data.
Blank keys need a policy as well. Excel’s model rules treat null and empty strings as the same blank value for the uniqueness check, so more than one blank can violate it. For the approved Stores and Products fixtures, require nonblank unique IDs because a blank cannot reliably identify a known store or product. This lesson uses the stricter business rule even though a single blank value is not itself the same thing as a duplicated lookup value. On the many side, separate a missing ID from the case where an ID exists but has no authorized lookup row.
Check domain membership after uniqueness. Microsoft notes that a relationship may be created even if the values in the two selected columns do not correspond. For instance, both Orders StoreID and Products ProductID are text. Type compatibility does not make those codes describe the same entities. A visible relationship line does not prove fact keys matched the intended lookup. Verify every source key against the lookup. Then use a valid filtered result to test the behavior of the actual relationship.
Find unmatched records before interpreting a blank category
On a disposable copy, change Orders O-112 StoreID from BLK-NSK-01 to a synthetic code ERR-STORE. Keep its approved ₹270 as a test value. The overall fact count and amount remain twelve and ₹2315. The named Nashik group loses this order and falls to ₹400 across two matched rows. Depending on the view, the unknown record can appear under a blank or unknown group. The sum of named-city values is now ₹2045, and the difference of ₹270 matches the rejected store key. A blank group can therefore represent real money with unresolved identity.
Use a manual match check for the small fixture. For a repeatable Power Query input review, make an audit-only query that uses a left anti join from Orders to Stores on the approved StoreID fields. This keeps Orders rows that have no matching store. Expect zero in the clean sample and exactly O-112 in the deliberately damaged copy. A left anti audit does not alter the source or complete the relationship. Use the rejected rows to request a correction or explicitly apply your organization's agreed unknown-member policy.
After identifying the problem, confirm the source was supposed to use BLK-NSK-01, restore it on the copy, update the affected model table, and refresh the relevant report. Nashik then returns to ₹670 and three rows. A PivotTable filter that hides the blank member might make the workbook look finished without repairing the missing link. Keep the rejected-key count visible to a reviewer even when reporting only approved named groups.
Test the separate Product relationship with an intersection
Swap the row dimension to Products Category. The original values are Dairy ₹480, Fruits ₹810, Staples ₹585 and Snacks ₹440. These sum to ₹2315. Then use a Pune filter and a Dairy filter together. Pune retains the five orders associated with its store. Dairy retains the rows associated with P01. Their intersection is O-101 and O-106, worth ₹320. The individual dimensions can both be correctly linked and still be used incorrectly in a report if the selected filter comes from the wrong field. Confirm the exact product and store key sets that reached the fact rows.
| Category | ProductID | Expected sum |
|---|---|---|
| Dairy | P01 | 480 |
| Fruits | P02 | 810 |
| Staples | P03 | 585 |
| Snacks | P04 | 440 |
Decide which key and path should be active
One dimension can have two valid jobs
Consider a separate two-order scenario. One purchase for ₹100 is placed January 31 and shipped February 1. Another for ₹200 is placed February 2 and shipped February 4. A Calendar can relate to order date and ship date. They are different timing questions. With the Calendar to order-date relationship active, February order sales total ₹200. A measure using the existing inactive ship-date relationship can return ₹300 for February shipments. Both answers can be correct at the same time because their date roles differ.
Excel's model expects a single effective path at a time. For the same pair of tables, the active relationship is used in normal analysis, and an inactive line is shown dotted or dashed. DAX USERELATIONSHIP can apply a pre-existing relationship within a calculation, changing the relationship used for that evaluation. The formula below is instructional and assumes a separate model with valid Date and ShipDate relationships, neither of which needs to be added to the main practice fixture yet.
Shipped Sales := CALCULATE([Total Sales], USERELATIONSHIP(Orders[ShipDate], Calendar[Date]))
Record the date role of the measure in its name so a reader never needs to infer whether February refers to ordering or delivery. A chart with the generic label “February sales” could otherwise mix the two meanings. Check Microsoft’s supported relationship and model behavior before designing alternate paths. Relationship changes can affect every report that uses the model. Test role changes and existing measures together on a copy.
Choose a single verified key when source identity spans fields
The Excel Data Model expects a single relationship column on each side. If a location code is unique only within a franchise, a raw code by itself might repeat. You can establish an approved single lookup key upstream representing the franchise and location together, then use the same key in the fact table. Verify that the encoding preserves uniqueness. Bare concatenation could turn the pairs 1 and 23, and 12 and 3, into the same text 123. Choose a controlled encoding or a source-assigned unique ID and rerun duplicate and coverage checks.
A direct many-to-many relationship is not available in the same way as a one-to-many relationship in the Excel Data Model. Do not treat a direct connection between repeated keys as an acceptable shortcut. If multiple memberships are legitimate, model them explicitly and check what should be counted, or seek a carefully designed lookup and measure calculation. A query merge that expands a repeated related key can multiply fact rows. It has a different purpose and consequence from an Excel model relationship. Review both the model rules and the business grain before using a complex structure.
Run the relationship and key coverage tests
Lab 1. Observe the report before and after connecting two tables
- Build the original three-table model on a copy and verify ₹2315 with a grand-total measure over Orders. Leave the Store relationship absent temporarily.
- Add Stores City and record the relationship warning or repeated unrestricted result. If the client creates relationships automatically, inspect the diagram and do the controlled before test only on a copy.
- Create the verified Store relationship. Check Pune ₹940, Nashik ₹670, Nagpur ₹355 and Solapur ₹350.
- Connect Products using ProductID and verify the four approved category amounts. Apply Pune and Dairy to check ₹320 from two known Orders records.
- Save the valid model and explain which subset you used to prove both links. Clear test filters before retaining the baseline.
Lab 2. Compare missing, duplicate and differently assigned lookup data
- In a disposable copy change O-112 StoreID to ERR-STORE. Do not change Amount. Update the model and record the unchanged grand total and Nashik’s lower amount.
- Identify the missing store code by hand or an audit-only left anti query. Expect one row worth ₹270. Restore the approved StoreID and verify the report recovers.
- On a separate input copy deliberately list BLK-PUN-01 twice in the Stores worksheet. Detect the duplicated key before creating a relationship or allowing a refresh. Record the rejected lookup and restore the clean input.
- In another clean model copy change the City label for the unique BLK-NSK-01 lookup row from Nashik to Pune, while leaving its key untouched. Pune would then include the old Nashik store orders as well and show ₹1610. The key coverage still passes. Restore Nashik after documenting the difference.
- Write the three independent outcomes: a missing fact key affects approved group coverage, a duplicated lookup violates uniqueness, and a valid changed label can legitimately reclassify existing facts.
Build a relationship review someone else can repeat
Map each fact key to exactly one intended lookup record
Use a small review worksheet with headings OrderID, Source StoreID, Approved Store Match and Approved City. Start with four visible controls from different cities. O-101 has BLK-PUN-01 and needs one Pune match. O-102 has BLK-NSK-01 and needs one Nashik match. O-103 has AMN-NGP-01 and needs one Nagpur match. O-105 has AMN-SLP-01 and needs one Solapur match. These facts prove four different relationships at the value level even though they all use one modeled edge.
In a worksheet Table separate from the model, you can count matches for a typed candidate StoreID as a quick independent check. The formula below expects a source store code in B2 of your review worksheet. It reads the approved Stores Excel Table, not the embedded model. It assumes the literal printed keys in this exercise. In a production set where identifiers include wildcard characters or different case policies, use an explicit match appropriate to the defined identifiers. The result for each printed source key should be one.
=COUNTIF(Stores[StoreID],B2)
Use the known broken codes to interpret the check. ERR-STORE gives zero. If you deliberately place two BLK-PUN-01 rows inside the practice Stores Table, the worksheet check returns two. A clean one-to-many model needs one approved lookup row per real store. This review is valuable before the relationship exists and after refreshing the accepted source. Comparing two codes by eye is much harder when a leading character, imported type or similarly named field differs.
Before adjusting a duplicate, compare the rest of its source fields. If a store changed where it operates, two rows with the same StoreID could intentionally represent two periods in a historical source. Choose a model key that identifies the intended historical row when you need historically accurate grouping. If the report uses today's description for every earlier order, retain only the approved current lookup record under that policy. These are different reporting decisions; removing the older row without understanding the data would silently choose one.
Compare three model states that share a grand total
| Test state | Raw fact amount | Expected grouped evidence |
|---|---|---|
| Approved relationship and keys | 2315 | Pune 940, Nashik 670, Nagpur 355, Solapur 350 |
| No city filter reaches the facts | 2315 | Client may warn; a displayed label can repeat the unrestricted amount |
| O-112 uses ERR-STORE | 2315 | Nashik 400, named cities 2045, unresolved 270 |
| Nashik store’s label changed to Pune | 2315 | Pune 1610, old Nashik store remains a matched lookup key |
Choose the correct repair from the state of the evidence. A disconnected field may call for a modeled relationship and the right report table. An unmatched code calls for an approved key correction or lookup row. The third changed issue describes a choice of classification, with an otherwise valid and unique relationship. If a classification change was intentional, the report can show ₹1610 under Pune. If the business needs the original city assignment, using a different measure or a financial adjustment will not restore the correct lookup history. Verify the dimension rule.
With the reclassification case, the new Pune result combines five previous Pune orders with three for the former Nashik label, making eight orders. It is also equivalent to the original FreshGo platform total of ₹1610, since the original Pune and Nashik stores share that platform in this fixture. Nagpur and Solapur use MarketRush and together contribute ₹705. When two different filters happen to select the same store set, their numeric results can agree. Check each report field’s business label and key scope even when expected money is the same.
Investigate a line drawn between structurally compatible but unrelated fields
In the model window, hover or inspect the properties of an existing relationship. Confirm the exact field of each table. A beginner can draw a connection between Orders StoreID and Products ProductID because both look like text identifiers. The first side here contains codes such as BLK-PUN-01, while the second contains P01 through P04. Each table has clean data independently, yet none of those values match between the chosen columns. If you tested that incorrect relationship on an isolated copy, a selection of P01 cannot identify any approved Orders StoreID. The lack of meaningful key matches explains the empty named-slice result.
Contrast this with an absent Product relationship. If no effective Product filter is applied, the unrestricted measure can remain ₹2315 under a category. If a structurally present but wrong relationship filters to no matching rows, an approved category can instead appear blank or absent. These are different clues. Start with the base measure, inspect the asserted key pair, and check one exact fact row before deciding to add, remove or redirect a link. Do not connect City itself to an unrelated field in Orders just because it would make the visual display a row.
When a valid relationship activates but the result is still surprising, clear test slicers one by one. The table might currently be on a date or product subset. For example, Pune and Dairy shows ₹320 over two orders. Pune and Fruits shows ₹270 over one order. Pune combined with a category that has no eligible orders in a separate test would yield no facts even if the relationship worked. Verify whether the expected comparison is a single filter or an intersection of filters before troubleshooting.
Use an exception report that leaves source data intact
With your authorized practice copies, you can represent the unmatched-id test in Power Query without altering either source. Start with the Orders and Stores queries as inputs, choose Orders as the left table and Stores as the right table, and select the approved StoreID on both. Pick Left Anti as the join type and inspect the Orders rows left by that query. Keep it named as an exception or review query. Do not load its rejected rows as the main Orders fact table. Its purpose is to reveal which fact rows failed to obtain one valid lookup record.
A left anti result answers whether at least one lookup match exists. It will not by itself find a lookup that has two duplicate matches. Review the lookup keys separately, for example by grouping approved StoreID records and counting the rows in each group, or using the worksheet check where there are few rows. These two checks are complementary. In the original clean fixture no fact row is unmatched and each of the four store keys occurs once in Stores. In the duplicate-store trial all Orders rows could still have at least one match while the lookup ambiguity fails approval.
Record the control amount for rejected rows before correcting them. With only O-112 unmatched, the rejected amount is ₹270 and the rejected row count is one. The missing calculation does not require the human reviewer to estimate how much one blank group represents. Keep the audit independent of the current chart filter. Once the source is corrected, rerun the exception check and the original known city analysis. It is possible to remove a fact row instead of correcting its key and falsely get no unmatched rows. Reconcile total sales and row counts again to detect that mistake.
Plan relationship naming and date role tests before wider use
Draw the diagram with Orders centered, Stores and Products beside it and a future Calendar clearly separated. Write the lookup key under each source name and the semantic relation under its line. If you place the tables in another visual order, the defined relationships do not change. Keep this one-page relationship map as a human reference. When a chart field changes, a teammate can verify which query and model table supplied it without reading several similarly named worksheet tabs.
Before adding a normal relationship that bridges two other tables, check for an existing route and what a filter might do along it. Excel imposes limits against ambiguous loops and direct many-to-many relationships. A classroom star-shaped layout can answer this workbook's known questions without unnecessary routes. If a future problem genuinely requires multiple date roles, first decide which role should be active. Test the other role with independent approved inputs and a clearly named calculation. Keeping the roles distinct helps prevent a valid-looking February total from answering the wrong time question.
In the tiny separate shipping example, a month slicer selecting February applies to the active date by default. The order-date measure reads the second ₹200 event, while shipping-date sales includes both the ₹100 and ₹200 events. Keep those calculations side by side if the report compares booked activity with shipment workload. Verify that changing the calculation does not unexpectedly change City or Product choices. The DAX expression uses one alternate relationship during its own evaluation and does not redefine which path the standard report uses.
Tell a legitimate empty intersection from lost lookup coverage
Some report cells should be empty even when every relationship is correct. Use the loaded sample and choose Nashik plus Dairy. Nashik’s approved orders contain two Fruits purchases and one Snacks purchase. None of its order rows uses P01, so a normal sales measure has no matching fact rows for its Dairy intersection. The same model still reports ₹670 for Nashik overall and ₹480 for Dairy overall. Check both individual slices before treating their empty intersection as a problem in the model.
Compare that valid empty cell to the rejected O-112 case. In that case the order still has a true amount and a product key from the printed fixture, but its changed store code no longer has a known city. The amount can still contribute to the full Fruits category of ₹810 when there is no city filter. When checking Nashik and Fruits together it is no longer included. The original ₹450 intersection falls to ₹180. This is a missing-model-map problem with a known ₹270 impact, not simply a case with no purchases. Show a row count along with a sales measure so your audience can investigate what actually contributed.
Record each failed check before clearing or changing filters. If several combinations are empty, ask whether only one dimension is involved, or whether the report has filters from more than one table. Using an unrelated second field can produce a missing or misleading combination. Read the selected source fields in the field list and compare the actual known fact IDs. A saved layout that hides empty combinations or groups can look tidier while reducing the evidence available to a student. Use a separate model review sheet before applying presentation choices.
Explain who can alter the relationship definition
In a small analysis file the same learner may own both sources and the model. In a shared report the source owner approves key assignments while the report author manages model relationships. Changing the data in Stores is different from changing which column the relationship uses. The first can reclassify a group within the same valid path. The second can affect every report that relied on the old path. Preserve a known-good workbook copy and write the approved key mapping before asking another person to refresh the report.
At the end of the exercise list the linked fields, one-side uniqueness, actual coverage counts and two known report outputs. Another reader should be able to check the relationship even if the current diagram places Stores below Orders or the application moved a command to a different ribbon location. Describe the relationship in terms of entities, keys and expected result rather than the box positions you saw.
Keep the exception report with its source date and Table version. If it finds no unmatched records after a refresh, confirm the approved Orders count is still twelve before concluding that all records were mapped. Verify the model and the source audit are evaluating the same accepted extract.
Explain the direction and effect of the relationship
Quiz
Which table is the one side of the Store relationship?
Stores. Each approved StoreID appears once there. Many Orders rows can use its StoreID.
Which fields create the Store relationship?
Orders StoreID on the many side and Stores StoreID on the unique lookup side. City is a descriptive grouping field.
What happens to Nashik after O-112 uses ERR-STORE?
Nashik's known slice falls to ₹400 across two orders. The raw model total still includes the unresolved ₹270.
Why is a drawn line insufficient evidence?
Excel can accept structurally compatible columns without verifying all source values correspond. Check lookup uniqueness, coverage and the intended filtered results.
Which amount verifies Pune and Dairy together?
₹320, from O-101 and O-106. The city and category filters must both reach Orders.
Interview questions and answers
What do you check when every city shows total sales?
Inspect the source of the PivotTable, which City field it uses, the active relationship path and the measure's treatment of filters. Check a known city subset.
How do you test the lookup key population before modeling?
Check its business identity, nonblank policy, compatible types and uniqueness. Check fact key coverage separately, for example by keeping unmatched orders in an audit query.
What is the difference between creating a relationship and reporting a lookup value?
The relationship defines filtering across related tables. A lookup field supplies a label used by the report. Verify the label groups the actual matched fact rows.
When might a model use an inactive relationship?
When two keys between the same tables represent different roles, such as ordering and shipping dates. A supported calculation can use the intended existing inactive relationship explicitly.
Why is OrderID allowed to differ from StoreID?
OrderID identifies an event at the approved order grain. StoreID identifies which unique store that record references. They are separate entities and can have different repetition patterns.
Revision cards
- One side. The selected lookup column must have unique key values.
- Many side. Several related facts can refer to the same lookup key.
- Coverage. Verify every accepted fact key resolves to the expected lookup record.
- Active path. The ordinary report follows the active relationship unless a measure deliberately chooses another.
- Known result. Check real slices, such as ₹940 for Pune and ₹320 for Pune and Dairy.
- Unresolved member. An unknown or blank category can carry real monetary values.
Review the original relationship comparison alongside the controlled cases, or practice in the Excel Practice Task Hub. Continue to designing facts and dimensions as a star schema.
Microsoft references
- Diagram View and active relationship rules
- Excel foreign and related key dialog
- Supported types, lookup keys and limitations
- Diagnosis of missing or suggested relationships
- Filter context and unmatched blank members
- USERELATIONSHIP and an alternate existing relationship
- Audit unmatched inputs with a left anti join
- Worksheet audit counts before modeling