Ravindra BagaleCourses & study guides मराठी Track your progress

Excel

24. Power Pivot and the Data Model

Build a sales report from several related tables

Priyanka Shinde tracks orders for a fictional grocery delivery company. The order file records when each purchase happened and how much it was worth. Store information lives in a separate list, with a city beside each store ID. Products have their own list with category labels. Priyanka wants to compare Pune and Nashik, and then split the same sales amount by grocery category. She can repeat a lookup on every order row. She can also teach Excel which tables describe each other once, then reuse that relationship in several reports.

The Excel Data Model is a collection of tables, relationships and calculations stored inside a workbook. An Excel workbook has at most one Data Model, and several PivotTables can reuse its contents. Power Pivot is the Excel add-in and editing environment that supports model work such as viewing relationships and creating DAX measures. Power Query handles getting and shaping source data. A PivotTable, chart or CUBE formula can display values from the prepared model. Keeping these jobs separate makes it practical to trace a wrong report from its number back to the source.

  • Identify what one row means. One order row, an order line and a daily store total answer different questions.
  • Filter through keys. A city label selects stores. Their IDs select the Orders rows that carry the sales values.
  • Verify more than the grand total. Model relationships can be absent or wrong even when the raw money column sums correctly.
A Pune filter selects Store S1 from Stores, then orders O1 and O2 from Orders. Amounts 100 and 200 sum to 300 rupees. Nashik order O3 is excluded.
City filters the store list. The model uses the resulting store ID to find matching rows when it calculates sales.

Separate the input, model and report jobs

Think about a fictional Blinkit-style workbook. A weekly export supplies order events and a store list supplies current store labels. A Power Query step can clean wrong spaces in identifiers or standardize dates before loading. A lookup relationship defines how a selected store relates to those events. A named measure provides a consistent way of calculating the current sales figure. The PivotTable chooses which breakdowns to show. If the business asks for sales by category next week, Priyanka can rearrange the report without pasting new product names into every orders worksheet row.

In a one-time check on a small file, a flat worksheet and a lookup may be enough. Model the data when you have a real reason: a shared store or product list, repeatable analysis of several tables, or consistent calculations across multiple reports. Relationships should describe the data people actually agree to use. They do not make imported amounts current by themselves, and changing a store's dimension record can reclassify historical sales under the model’s current lookup values. Capture approved history separately when that difference matters.

Follow a three-order example from the source to the answer

Use this small teaching fixture for the overview. The longer numbered lessons use the original twelve-order dataset with four cities. This example deliberately contains just three rows and two store keys, so you can verify the relationships by hand. The example company and amount are fictional. “Order” means one approved row per order in this initial exercise. Later in the page we switch to an explicitly separate line-level exercise to see what that choice changes.

Orders. Each row records one approved order in the initial fixture.
OrderIDOrderDateStoreIDProductIDAmount in rupees
O12026-09-01S1P1100
O22026-09-02S1P2200
O32026-10-01S2P2300
Stores. Each StoreID represents exactly one lookup row.
StoreIDCity
S1Pune
S2Nashik
Products. Each ProductID represents exactly one product in this example.
ProductIDCategory
P1Dairy
P2Fruits

Identify the table that holds measurable events

An Orders row carries an amount, a date and keys for the entities associated with it. This is a fact table in the example. Its grain is one thing represented by each row, here one order. A dimension table gives us descriptive fields for grouping, such as City and Category. Stores has one row per store and Products has one row per product. When Stores[StoreID] is unique, several orders can use an S1 reference without changing which one store they mean. The key on the Orders side is allowed to repeat. The key in the approved lookup must identify one row.

People sometimes read a repeated StoreID in Orders as a duplicate order. That would be a mistake. O1 and O2 are different purchases from the same store. Check the identity appropriate to the grain. The fact order key is OrderID in this three-row model. StoreID tells you which store it references. Later, if the input has multiple lines per order, OrderID can legitimately repeat there too. The suitable line key would then identify each distinct order line. Classify the rows before using any tool that removes duplicates.

Read the filter relationship in both cause and effect

In a supported Excel model create the relationship using Orders as the many-side table, Orders StoreID as the foreign column, Stores as the related lookup table and Stores StoreID as the related key. Apply the same pattern between Orders ProductID and Products ProductID. The UI can distinguish the one and many sides. For this example filters from the lookup Store or Product tables narrow the related Orders rows. A PivotTable with Stores City can ask the measure to sum only orders whose StoreID belongs to that city.

When Pune is selected, Stores keeps S1. Orders retains O1 and O2 through the relationship, giving 100 plus 200, or ₹300. Nashik keeps S2 and counts one order worth ₹300. The displayed sales happen to be equal. The counted orders tell different stories about the source, so verify both measures. If the product category is Fruits as well, Pune's eligible orders narrow to O2 and sales become ₹200. A filter can narrow the fact rows along more than one approved relationship at a time.

Loading tables places their data in the model. Creating a relationship records how key values connect them. It does not merge all fields into every Orders row. If you need a flattened export with category data on each order, that is a separate load or join decision. For analysis, separate dimension fields remain available for rows, columns or slicers. This is also why adding tables to the model does not prove that they can filter one another. Review both the relationships and a known report slice.

Name a calculation and let the report supply its context

DAX stands for Data Analysis Expressions. It is the calculation language used for the model. A measure is a named calculation evaluated for a particular set of filters. A cell at the intersection of Pune and Fruits can have both filters active. The grand total normally evaluates the same measure in the grand-total context rather than adding every previously displayed result. Additive sales amounts can coincide with displayed subtotals, while ratios and distinct counts often behave differently. A measure definition persists in the model, and its results depend on the query context.

Use the formulas below as definitions in the model rather than typing them into an ordinary grid cell. In the Excel Power Pivot New Measure dialog choose Orders as a home table, enter the measure's name, and enter the expression after the leading equals sign. The block uses label and formula notation so you can read each full definition. Excel versions can expose a Measures command or Calculation Area. The lesson on measures walks through the UI and narrower DAX examples.

Total Sales := SUM(Orders[Amount])
Order Rows := COUNTROWS(Orders)
Unique Orders := DISTINCTCOUNT(Orders[OrderID])
Sales per Order := DIVIDE([Total Sales], [Unique Orders])
Expected report contexts for the three-order example.
Filter contextSalesOrder rowsUnique ordersSales per order
All eligible orders60033200
City Pune30022150
City Nashik30011300
Category Fruits50022250
Pune and Fruits20011200

In the clean order-grain fixture, COUNTROWS and DISTINCTCOUNT agree because every approved row has one unique known OrderID. They need not agree in other data. DISTINCTCOUNT includes a blank value when such a key is present. Correct missing IDs or define an approved blank-exclusion measure before describing the value as the number of actual purchases. An empty filtered table can return BLANK from COUNTROWS. A PivotTable can hide empty combinations or style a blank. Interpret the underlying measure and source coverage before deciding a blank means zero sales.

Keep per-row fields separate from report-level calculations

A calculated column produces a result for each row, such as a calculated band naming amounts at least ₹200. That column has one stored result per modeled row at calculation time and can help group or filter a report. A measure calculates a result for the currently filtered set, such as ₹200 for Pune and Fruits or ₹600 for the unfiltered total. The formula is stored as a model object, without placing a separate copy of its value in every Orders row. Both can be useful for a specific purpose.

In this fixture, order O1 has an amount of 100 and can be assigned Below 200 in a calculated column. O2 and O3 can each receive 200 or more. Grouping by that field would give one group worth ₹100 and another worth ₹500. A measure can show the sum in each group. Repeating a report total in an Orders calculated column would confuse a row-level attribute with a context-specific aggregate. Choose the model object based on whether you need a reusable group label or a reusable summarized result.

Diagnose a grand total that passes while detail fails

See why repeated totals call for a relationship test

Imagine a report with Products Category in Rows and the sales measure in Values. The grand total is ₹600. Dairy also appears as ₹600 and Fruits as ₹600, if the report is able to display the disconnected group without a relationship warning. The raw sales measure can still add three valid amounts. The category selection has not filtered those rows. Check that the PivotTable reads the correct model and its actual Products field. Then inspect the relationship from unique ProductID to Orders and test the expected Dairy and Fruits values of ₹100 and ₹500.

That symptom has more than one possible cause. A custom measure might deliberately remove product filters. An independently loaded category lookup might be disconnected. A PivotTable may be based on the wrong model or source. Use a base sales measure that does not alter the filters, check actual participating table names, and inspect the relationship before editing the formula. Confirm the row counts and category values from the source independently. With approved keys the base measure should produce the small known slices. A passing grand total remains a useful but incomplete check.

Without a product filter path the categories can both show the 600 grand total. With the correct key relationship Dairy is 100 and Fruits is 500; the grand total stays 600.
Two reports can share a correct grand total. Check a category with a unique known slice to prove the relationship works.

Follow two filters into the same fact table

  1. Read the complete approved sample

    All three order rows contribute. Their amounts sum to ₹600. The order count is three.

  2. Select the city

    Pune selects S1. Model orders O1 and O2 have that store, so Pune gives ₹300 from two records.

  3. Select a product category too

    Fruits selects P2. Its intersection with the surviving Pune orders is only O2. Sales becomes ₹200.

  4. Change the question deliberately

    Clear the city selection. Fruits now includes O2 and O3, so the result is ₹500. Confirm each included order ID.

Separate a repeated fact from a distinct identity

Make a disposable copy of the small sample and duplicate O2 with the original ₹200. The source now contains four rows worth ₹800. Unique Orders remains three because the identifiers are O1, O2 and O3, so the calculated sales per order becomes roughly ₹266.67. DISTINCTCOUNT cannot repair an overstated Sales total. Find why there were two identical order-grain records and accept a corrected input under the source policy. Validate the raw sum and the order count separately after the correction.

A valid line-grain example illustrates the other direction. In another copy remove the original single ₹200 O2 row and replace it with two legitimate O2 lines, one Dairy at ₹100 and one Fruits at ₹100. Distinct order count remains three while fact row count is four, and sales is still ₹600. Dairy now involves O1 and O2. Fruits involves O2 and O3. Adding two distinct counts from those groups would give four. Overall the model correctly reports three unique orders because O2 is present in both categories. This is why a grand total of distinct counts can differ from the sum of displayed cells.

Build and challenge the overview model

Lab 1. Use the three approved tables in one PivotTable

  1. Start with a new practice workbook and create named Excel Tables Orders, Stores and Products from the three small inputs. Use text for the example keys and numeric amounts for Orders Amount. Enter true dates if you later use the source dates for model filters.
  2. In compatible desktop Excel add each Table to the Data Model using supported model commands, and verify it is present. On a Windows setup with Power Pivot, enable the appropriate Excel add-in and inspect Manage.
  3. Create the StoreID and ProductID relationships with their unique lookup sides. Check that the model uses the same ID types and names printed above.
  4. Create the model measures. Insert a PivotTable from the workbook Data Model and verify the all-order summary of ₹600 over three rows.
  5. Use Stores City in the rows and Products Category in a filter or second axis. Check Pune ₹300, Fruits ₹500, and the joint Pune/Fruits ₹200. Compare the order IDs manually before trusting the model.

The native modeling steps in this course use a supported Windows desktop edition of Excel with the Microsoft Power Pivot add-in. Excel on Mac and the web may offer similar-sounding query or PivotTable features without the same model editing interface or capabilities. Read the current Microsoft Excel feature documentation for your installed client. You can work through the evidence with the printed tables even when your client cannot reproduce the native authoring steps. Use Excel's worksheet functions for an independent arithmetic check, without assuming they run the model itself.

Lab 2. Compare a valid model with deliberately damaged input

  1. Save a clean baseline and work on a copy. Use Diagram View to inspect or temporarily remove the Products relationship in the copy only.
  2. Compare the observed PivotTable behavior with a hand calculation. If the report warns about a missing relationship, record the warning. Without any product filter reaching Orders, the unrestricted value is ₹600. Restore the relationship and verify Dairy ₹100 and Fruits ₹500.
  3. In another disposable copy add the repeated O2 record inside the source scope. Apply the supported model update and recalculate. Check four source rows, ₹800 across the facts and three distinct IDs. Restore the approved source.
  4. Use the separate two-line O2 variation. Predict the category records on paper first. Verify four rows, three distinct order IDs and ₹600 total. Dairy and Fruits each include two distinct orders, while the report still has three overall.
  5. Keep one clean baseline and record which failure came from relation scope, which came from duplicated money and which depended on the approved row grain.

A relationship or source update can require you to refresh data and recalculate the model or the report. Worksheet edits, connector refresh completion and recalculated PivotTable values are separately observable. Inspect the source membership and model row counts after the change. If a result fails to update, establish whether the intended data was loaded before changing a DAX expression. Maintain only the clean sample model as the source for the next lesson.

Build a small acceptance plan before expanding the model

Audit the two sides of every relationship

A beginner can check the Stores join on paper. Underline each StoreID listed on the one side. Then scan the Orders rows and record which lookup ID each uses. In the original fixture S1 appears twice in Orders and once in Stores. S2 appears once in Orders and once in Stores. These are good matching patterns. Add a second lookup row for S1 and you jeopardize the uniqueness requirement on the Stores side, even if there is no duplicate in Orders. Out of two rows giving conflicting names for S1, the model would have no one approved lookup record for the relationship.

For a missing-match exercise, change only Order O3's StoreID from S2 to S9 on a test copy. This row still contains valid sales of ₹300. The raw facts sum to ₹600. A Pune city filter can still yield ₹300. The amount can disappear from the named Nashik group, since S9 has no store record. Some model reports can show an unknown or blank member for such facts. Verify the actual unmapped key and decide whether the row is approved, the lookup is incomplete or the ID is wrong. Cover every approved fact key before publishing a labeled city breakdown.

Record the expected totals with both ID and business label. A common error in source solutions is joining on City because it is familiar to a reader. If two stores belong to Pune then Pune itself repeats within Stores, and the report needs their distinct StoreIDs. A shared city group can validly select both IDs, and Orders then includes those matching store records. A relationship key should identify a lookup row consistently. A grouping attribute is allowed to share its value across multiple lookup rows.

Check the data type as well as the printed characters. In source exports, the ID 001 can arrive as text in one table and 1 as a number in another. Converting both to numbers removes leading zeros and might combine codes that have distinct meanings in the real source. Agree on the canonical type, preserve raw keys while cleaning, and confirm the result using a match check on a copy. Fix wrong leading or trailing characters with a defined rule rather than typing a substitute wherever the PivotTable looks odd.

Verify periods beyond the set of dates on sales receipts

The three original orders have dates in September and October. On paper the September slice contains two orders worth ₹300. The October slice contains one order worth ₹300. These facts do not establish whether the company sold nothing on other days or whether the extract contains every eligible order. A data owner must declare coverage. The presence of a record on October 1 doesn't determine that October is partial, and the two September dates don't prove all September was loaded. Set a matched approved period before interpreting a month comparison.

If Priyanka wants calendar month filters and periods with no orders, she can use a separate date dimension with one checked row per date for the required interval. The fact date keys must be comparable to its date values. An imported timestamp can contain a time part even if cell formatting only displays the day. Normalize the defined date used by the report while preserving any required source timestamp. A PivotTable can then use a year-aware month label from the calendar and apply the related date filter to Orders. This is the same general model flow as city filtering, with a date lookup rather than a store lookup.

When comparing October with September, write whether the report uses completed months, equal elapsed days or another agreed date window. A measure can calculate the prior period defined by its DAX function. That does not decide whether the two source periods are complete or comparable enough for the business. If earlier approved data exists, the first visible month can have a populated previous month even when it is the first row currently displayed. The date and prior-period lessons will test these cases in detail.

Build independent controls for data and filter logic

A short set of expected observations for the clean overview model.
QuestionExpected evidenceWhat it tests
How much sales data arrived?Three Orders rows, ₹600Accepted fact coverage and raw amount
Which city records use S1?O1 and O2, ₹300Lookup table identity and relationship
Which category records use P2?O2 and O3, ₹500Product identity and relationship
Which records satisfy both conditions?Pune and Fruits: O2, ₹200Both lookup filters reach the same fact table
How is the combined average calculated?₹600 divided by three distinct known ordersCorrect population and per-order measure

Review these before opening a chart or designing a card. A pretty report with a repeated grand total may be hard to diagnose after adding slicers. Start with one base measure and a verified field from one dimension. Add another dimension only after the first slice succeeds. When a known city stays at ₹300 but the count changes, review the fact rows and order keys. When both city and product slices fail after a source refresh, check whether the correct loaded tables and relationships survived first.

Use the separate calculation measure to tell apart a changed filter and a changed source. One test keeps all input rows as approved and changes the selected City. A second test keeps the selection unchanged and approves a new input amount in an isolated copy. Record the source version and selected value so the person grading both scenarios can tell which action produced the result. Keep at least one known unchanged value to prove the scope of the effect as well as the size.

Preview what a calculation can do to an existing filter

Suppose the manager asks for a measure that always answers for Pune while still responding to the selected product category. The base sales calculation already responds to all current filters. A new CALCULATE definition can evaluate it with a Pune condition on Stores City. This changes that measure’s calculation context. It has no effect on the stored Orders rows and does not permanently change the report’s city selector.

Pune Sales := CALCULATE([Total Sales], Stores[City] = "Pune")
Pune Sales within selection := CALCULATE([Total Sales], KEEPFILTERS(Stores[City] = "Pune"))

If the report explicitly filters Stores City to Nashik and Products Category to Fruits, the ordinary Total Sales measure returns ₹300 from O3. The first Pune Sales measure replaces the filter on the same Stores City field with Pune, keeping the Fruits condition. It returns ₹200 from O2. The second applies the Pune condition as an intersection using KEEPFILTERS. Nashik and Pune cannot both be selected under that explicit context, so there are no matching sales rows and the sum is blank. Other filters and relationship paths still need review in a more complex model.

Before naming a DAX measure, state which scope it changes. “Pune Sales” can describe a deliberate city override, while “Pune Sales within selection” implies the existing city selection is respected. In a review, use a case where those definitions produce different results. Overall both definitions can give ₹300 with no explicit City or Category filter, so that one total would not test the difference. Adding the known Nashik and Fruits slice creates enough evidence to check the intended behavior. The later DAX lesson takes the idea into the twelve-order fixture and explains which related filters remain active.

This also helps you interpret the original revision card correctly. Its Pune calculation evaluates a separate customer example with no conflicting City filter: two Pune customer orders of ₹500 and ₹200 versus ₹1000 overall. It is a clear first test of CALCULATE. Carry the more specific City overwrite test into exercises with a city slicer or a PivotTable row using the same dimension field.

Move from workbook model to reusable reporting deliberately

Model structure becomes important when more than one report depends on the same totals. If three workbook PivotTables point at approved model tables and use one Total Sales measure, a confirmed change to its definition can affect all three. Give that calculation a clear name and keep an approval note defining which amount it sums. Test expected outputs in every representative report before swapping definitions. If a separate report needs shipped sales while others need ordered sales, create distinct definitions with explicit business meaning.

CUBE formulas can give cell-level placement for selected model measures and members in supported Excel clients. A PivotTable provides an interactive grouped view. Both should agree when they use the same measure, connection and filters. A manually arranged report sheet can make individual labels easier to place, but it still needs a traceable model source. The dedicated PivotTable and CUBE lesson compares exact cells rather than assuming any accessible chart shows the same filters.

Excel can suit a model used by a small team working directly with its approved workbook. A team that needs a managed reporting service, scheduled updates and governed viewer roles has a broader decision to make. Power BI reuses concepts such as fact and dimension tables and DAX measures. Some features, source access and sharing rules differ. Work out who will author the model, who can view it and which source can refresh before deciding whether to move a report. The goal is reliable audience access, not a particular row count or an icon on the desktop.

Use this overview to learn the logic while the sample is still easy to count. The twelve-row numbered fixture expands to four cities and four product categories. Its correct all-data sales amount is ₹2315. It also gives different city, category and period totals for checking filter propagation. Preserve that fixture’s original values as you progress. If you start with this three-order overview file, treat it as a separate named model so an earlier expected control of ₹600 cannot be mistaken for a later data-load problem.

Before starting the twelve-order dataset, close the overview model and give the new file a separate name. Record the count of source orders and total sales next to the filename. If a later PivotTable shows only two cities or still shows ₹600, check which model it reads before changing its relationship rules. A named source version and a distinctive expected amount make that mix-up easier to catch.

As a final hand check, explain why the clean example can give the same sales total for two cities while the ratio per order differs by a factor of two.

Choose the next lesson by the problem you need to solve

Keep this introduction's three orders separate from the original twelve-order numbered dataset and the eight-order capstone. A correct calculation is meaningful only when its inputs and expected scope match. These exercises give you different test cases for relationships and measurements, with the same underlying questions about identity, totals and filters.

Explain the flow from source to measure

Quiz

Which field determines the city for each order?

Orders contains StoreID, and Stores contains the city for that same ID. The relationship uses the IDs to let a city selection filter the appropriate orders.

Which approved rows are in Pune and Fruits together?

Only O2. Pune retains S1 orders and Fruits retains P2 orders. Their common record has ₹200.

Why can ₹600 on every product category be a warning?

The category filter may not restrict the Orders rows. With this fixture Dairy should show ₹100 and Fruits ₹500. Inspect the relationship and the measure's filters.

Will DISTINCTCOUNT fix the duplicate O2 amount?

It still counts three unique IDs, but the money measure sums four rows worth ₹800. Clean the facts using the approved record identity before calculating.

What is the grain of the first fixture?

One row per approved order. The second practice version changes to one row per order line, so the row and order count answer different questions.

Interview questions and answers

What does Power Pivot add to an Excel analysis?

It provides a supported model editing environment to inspect relationships and build reusable calculations. The Data Model stores the related tables and measures. Reports can use those model objects.

What would you check before creating the Store relationship?

Check that Stores StoreID identifies one lookup row, fact keys match the approved reference values, and both fields have compatible types. Compare a known ratio or subtotal after connecting them.

How do you choose a calculated column or a measure?

Use a column for a per-row modeling field or category, and a measure for a result evaluated in the report's current context. For example an amount band describes a row, while total sales sums selected Orders rows.

Why does a distinct-count grand total differ from the sum of categories?

One order can be represented in more than one category. The grand total evaluates unique IDs across all selected rows and counts each one once.

How would you find a source refresh problem?

Confirm the expected source rows were actually approved and loaded, then inspect model row counts, relationship coverage and recalculated report slices. An unchanged total alone is insufficient evidence.

Revision cards

  • Grain. State what each row represents before choosing a count or total.
  • Dimension. A keyed lookup table supplies fields for grouping and filtering.
  • Fact. The events or observations contain the amounts and keys used by the analysis.
  • Relationship. Matching keys allow approved lookup filters to reach the facts.
  • Measure. A named calculation is evaluated in the current filter context.
  • Validation. Check coverage and one known slice alongside the total.

Download the original relationships and CALCULATE card or calculated columns and measures card. The first card uses a separate customer example. The second card's distinct count assumes approved identifiers. Find more in Ravi Sir's Cards or use the Excel Practice Task Hub.

Microsoft references