Build it or open the example

Download the sample workbook as a ZIP, extract it and open the XLSX. If you'd like to build it yourself, start with the September and October order data. The queries prepare each month's orders once. The data model then lets a reader change the month, product or department without asking accounting for another report.


Why add a data model?

The first question I get after comparing September with October is usually about the rest of the year. Then someone wants one department, and somebody else wants a product category. I want one set of order rows to answer all three questions. Power Query gives those rows a dependable shape. Power Pivot lets the same measures respond to different selections.


The four tables to start with

Paste each block into its own Excel sheet. The headings and sample values here use the Korean field names required by the supplied M and DAX. In particular, 발주번호 is the order number, 부서 the department, 제품명 the product, 금액 the amount and 발주일자 the order date.

September purchase orders

발주번호    제품명 부서  수량  단가  금액  발주일자
PO-001  노트북 IT팀 5   1500000 7500000 2024-09-05
PO-002  모니터 IT팀 10  300000  3000000 2024-09-08
PO-003  의자  관리팀 20  150000  3000000 2024-09-10
PO-004  책상  관리팀 15  200000  3000000 2024-09-12
PO-005  프린터 영업팀 3   500000  1500000 2024-09-15
PO-006  태블릿 영업팀 8   800000  6400000 2024-09-18
PO-007  키보드 IT팀 30  50000   1500000 2024-09-20

October purchase orders

발주번호    제품명 부서  수량  단가  금액  발주일자
PO-001  노트북 IT팀 5   1500000 7500000 2024-10-05
PO-002  모니터 IT팀 12  320000  3840000 2024-10-08
PO-003  의자  관리팀 20  150000  3000000 2024-10-10
PO-005  프린터 영업팀 5   480000  2400000 2024-10-15
PO-006  태블릿 영업팀 10  850000  8500000 2024-10-18
PO-008  스캐너 관리팀 2   1000000 2000000 2024-10-22
PO-009  회의용TV   영업팀 1   3000000 3000000 2024-10-25

Department lookup

부서코드    부서명 부서장 인원수
DEPT-01 IT팀 김철수 15
DEPT-02 관리팀 박영희 8
DEPT-03 영업팀 이민수 20

Product lookup

제품코드    제품명 카테고리    공급업체
PROD-01 노트북 IT장비    A사
PROD-02 모니터 IT장비    B사
PROD-03 의자  사무가구    C사
PROD-04 책상  사무가구    C사
PROD-05 프린터 사무기기    D사
PROD-06 태블릿 IT장비    A사
PROD-07 키보드 IT액세서리  E사
PROD-08 스캐너 사무기기    D사
PROD-09 회의용TV   회의실장비   F사

Prepare the monthly rows in Power Query

Turn the ranges into named tables

Select each range, choose Insert → Table (Ctrl+T in Windows), and confirm that the first row contains headings. Name the four tables Orders_September, Orders_October, Departments and Products so the queries can find them.

Append September and October

let
    // Tag the September orders with a period.
    Sept = Excel.CurrentWorkbook(){[Name="Orders_September"]}[Content],
    SeptWithPeriod = Table.AddColumn(Sept, "Period", each "2024-09"),
    SeptWithSource = Table.AddColumn(SeptWithPeriod, "DataSource", each "September"),

    // Tag the October orders with a period.
    Oct = Excel.CurrentWorkbook(){[Name="Orders_October"]}[Content],
    OctWithPeriod = Table.AddColumn(Oct, "Period", each "2024-10"),
    OctWithSource = Table.AddColumn(OctWithPeriod, "DataSource", each "October"),

    // Append the two tables.
    Combined = Table.Combine({SeptWithSource, OctWithSource}),

    // Assign column types.
    TypedData = Table.TransformColumnTypes(Combined, {
        {"발주번호", type text},
        {"제품명", type text},
        {"부서", type text},
        {"수량", Int64.Type},
        {"단가", Currency.Type},
        {"금액", Currency.Type},
        {"발주일자", type date},
        {"Period", type text},
        {"DataSource", type text}
    }),

    // Build a row signature for comparison.
    AddRowHash = Table.AddColumn(
        TypedData,
        "RowHash",
        each Text.Combine({[발주번호], [제품명], Text.From([수량]), Text.From([금액])}, "|"),
        type text
    ),

    // Number repeated keys.
    GroupedWithIndex = Table.Group(
        AddRowHash,
        {"발주번호", "Period"},
        {{"AllRows", each Table.AddIndexColumn(_, "DupIndex", 1, 1), type table}}
    ),

    // Expand the non-key fields dynamically.
    ColumnsToExpand = List.Difference(
        Table.ColumnNames(AddRowHash) & {"DupIndex"},
        {"발주번호", "Period"}
    ),

    FinalTable = Table.ExpandTableColumn(
        GroupedWithIndex,
        "AllRows",
        ColumnsToExpand,
        ColumnsToExpand
    )
in
    FinalTable

Name the appended query Orders_Combined. The period attached to each row will let us compare months in the same PivotTable.

Create a separate change report

let
    // Start from the appended order query.
    Source = Orders_Combined,

    // Keep September rows.
    SeptData = Table.SelectRows(Source, each [Period] = "2024-09"),

    // Keep October rows.
    OctData = Table.SelectRows(Source, each [Period] = "2024-10"),

    // Full Outer Join
    Joined = Table.NestedJoin(
        SeptData, {"발주번호", "DupIndex"},
        OctData, {"발주번호", "DupIndex"},
        "October",
        JoinKind.FullOuter
    ),

    // Expand the October fields.
    Expanded = Table.ExpandTableColumn(
        Joined, "October",
        {"제품명", "부서", "수량", "단가", "금액", "RowHash"},
        {"제품명_Oct", "부서_Oct", "수량_Oct", "단가_Oct", "금액_Oct", "RowHash_Oct"}
    ),

    // Classify the change.
    AddChangeType = Table.AddColumn(
        Expanded, "ChangeType",
        each
            if [RowHash] = null then "Added"
            else if [RowHash_Oct] = null then "Removed"
            else if [RowHash] = [RowHash_Oct] then "Unchanged"
            else "Modified",
        type text
    ),

    // Calculate the difference.
    AddDifference = Table.AddColumn(
        AddChangeType, "금액차이",
        each
            if [ChangeType] = "Modified" then [금액_Oct] - [금액]
            else if [ChangeType] = "Added" then [금액_Oct]
            else if [ChangeType] = "Removed" then -[금액]
            else 0,
        Currency.Type
    )
in
    AddDifference

Name this query Comparison_Results. The combined table answers “How much did we order?” The comparison answers “Which rows changed?”


Build the Power Pivot model

Load the tables

The steps here use desktop Excel with Power Pivot. Load Orders_Combined, Comparison_Results, Departments and Products to the workbook's Data Model. Open Power Pivot → Manage to check that each table has a tab.

Connect the lookups

Open Diagram View. The orders table can contain the same department or product many times. Each matching name must occur just once in its lookup.

Department: Orders_Combined[부서] → Departments[부서명]
Product:    Orders_Combined[제품명] → Products[제품명]

Use active one-to-many relationships with filtering from the lookup table to the order rows. Keep Comparison_Results as a separate report. Dragging a field from an unrelated table won't magically make its filters work.

Add a calendar

Create a date table in Power Query with one row per day across the order range, and columns for year, month and weekday. Name it 달력 (“calendar”) to match the examples. Alternatively, generate the range with DAX in a version that supports calculated tables.

달력 =
CALENDAR(
    DATE(2024, 1, 1),
    DATE(2024, 12, 31)
)

Connect the order date to the unique calendar date with this relationship: Orders_Combined[발주일자] → '달력'[Date].


Give the model reusable measures

Keep the order totals near Orders_Combined, time comparisons with the calendar, and change counts near Comparison_Results so the next person can find them. A measure's home table is an organizational choice. In the formula, quote a table name such as '달력' and use the field names exactly as they appear in the workbook.

The basic measures

In the New Measure dialog, choose the home table and name the measure. The formula field takes an expression beginning with =, for example =AVERAGE(Orders_Combined[금액]). That makes an average that can recalculate under a department or period filter.

You can also enter a named measure directly in the Power Pivot calculation area. The syntax there is 측정값이름:=수식. For example, Avg_Order_Amount:=AVERAGE(Orders_Combined[금액]). Put these first measures on Orders_Combined.

// Count orders. In the measure dialog start the formula with =.
Total_Orders = COUNTROWS(Orders_Combined)

// Total order value
Total_Amount = SUM(Orders_Combined[금액])

// Average order value
Avg_Order_Amount = AVERAGE(Orders_Combined[금액])

// Count distinct products.
Unique_Products = DISTINCTCOUNT(Orders_Combined[제품명])

The dialog takes = in its formula field. The calculation area accepts a name and expression together, 측정값명:=수식.

Compare periods and count changes

For the time measures, use the calendar column related to the orders. It's the sequence of dates that makes a prior-period comparison meaningful.

// Amount in the previous period
// Use the actual calendar table and date column in your workbook.
// Example 1. Quote the workbook's Korean calendar name.
Previous_Period_Amount =
CALCULATE(
    [Total_Amount],
    DATEADD('달력'[Date], -1, MONTH)
)

// Example 2. Use the date in Orders_Combined directly if there is no calendar relationship.
Previous_Period_Amount_Alt =
CALCULATE(
    [Total_Amount],
    DATEADD(Orders_Combined[발주일자], -1, MONTH)
)

// Percentage change from the prior period
Period_Change_Rate =
DIVIDE(
    [Total_Amount] - [Previous_Period_Amount],
    [Previous_Period_Amount],
    0
)

Put the change counts on Comparison_Results. That is where Added, Modified and Removed live.

// Count modified orders.
Modified_Orders =
CALCULATE(
    COUNTROWS(Comparison_Results),
    Comparison_Results[ChangeType] = "Modified"
)

// Count new orders.
New_Orders =
CALCULATE(
    COUNTROWS(Comparison_Results),
    Comparison_Results[ChangeType] = "Added"
)

// Count removed orders.
Removed_Orders =
CALCULATE(
    COUNTROWS(Comparison_Results),
    Comparison_Results[ChangeType] = "Removed"
)

Year-to-date and other comparisons

With a working date relationship, the calendar can also drive a running total and a comparison with the corresponding period last year.

// Year-to-date order value
YTD_Amount =
CALCULATE(
    [Total_Amount],
    DATESYTD('달력'[Date])
)

// Three-month moving average
Moving_Avg_3M =
CALCULATE(
    AVERAGEX(
        DATESINPERIOD('달력'[Date], LASTDATE('달력'[Date]), -3, MONTH),
        [Total_Amount]
    )
)

// Optional measure for the value of the five leading products
// Measure name: Top_5_Products_Amount
// Enter this expression in the formula field.
=CALCULATE(
    SUM(Orders_Combined[금액]),
    FILTER(
        ALL(Products[제품명]),
        RANKX(ALL(Products[제품명]), SUM(Orders_Combined[금액]), , DESC) <= 5
    )
)

// For a fixed selection of products, filter by name.
// =CALCULATE(SUM(Orders_Combined[금액]), Products[제품명] IN {"노트북", "모니터", "키보드", "마우스", "프린터"})

Make a PivotTable people can explore

The first view

Insert a PivotTable from the Data Model. First confirm these three joins in Diagram View: Orders_Combined[부서] → Departments[부서명], Orders_Combined[제품명] → Products[제품명] and Orders_Combined[발주일자] → '달력'[Date]. Use Period or DataSource for rows, the department name from Departments for columns, and Total_Amount for values. A product or category filter should now change the total because there is a real path from the lookup to the fact rows.

A blank member deserves investigation. Look for an order date outside the calendar, a missing product or department, or a key with the wrong type.

A view of the changes

Rows     Comparison_Results[ChangeType]
Columns  Comparison_Results[부서]
Values   Count of 발주번호; sum of 금액차이

A small report might look like this. The cells are counts of orders.

Change         IT    Admin    Sales    Total
Added           0        1        1        2
Modified        1        0        2        3
Removed         1        1        0        2
Unchanged       2        1        0        3

Put frequent filters within reach

Add slicers for period, department and product category to the related order views. A ChangeType slicer belongs with the change report. Use the slicer's report connections to select the PivotTables it can actually filter.

Let a change show at a glance

The four statuses need recognizably different formatting. Pair color with text or a symbol so readers needn't identify a change by color alone.

Added: green     Modified: yellow     Removed: red     Unchanged: gray
Increase ▲       Decrease ▼           No change ●

Choose a chart for each question

Is spending moving up or down?

Select the PivotTable and insert a line PivotChart. Give it Period or calendar YearMonth along the horizontal axis and Total_Amount on the vertical. To see separate lines, split by department. A product-category filter can narrow the view.

Which departments account for the difference?

Use a column PivotChart. Put the department lookup on the row axis, Period across columns and Total_Amount in values. Filter to one product or category when a department comparison needs explaining.

How is the change report divided?

Build this chart on Comparison_Results. Put ChangeType in rows, count purchase order numbers in values and show percentages on the pie or doughnut chart. Check what the denominator contains before describing a slice as the share of all orders.

Three numbers for the top of the page

Give the reader the scale of purchasing, the direction of movement, and the number of changes before asking them to interpret a chart.

Total order value    ₩45,240,000
Month over month         +15.3%
Changed orders                5

Arrange the refresh

Choose the connection settings

Data → Connection Properties
Refresh when opening the workbook
Allow background refresh where the connection supports it
Optional interval: every 60 minutes

Respect the dependencies

Begin with Orders_September and Orders_October. Orders_Combined depends on both, and Comparison_Results follows the prepared input. The model and its reports should refresh after their data is ready.

A button for the recurring job

Sub RefreshAllData()
    ' Refresh the queries.
    ActiveWorkbook.RefreshAll

    ' Refresh the data model.
    ActiveWorkbook.Model.Refresh

    ' Refresh the PivotTables.
    Dim pt As PivotTable
    Dim ws As Worksheet

    For Each ws In ThisWorkbook.Worksheets
        For Each pt In ws.PivotTables
            pt.RefreshTable
        Next pt
    Next ws

    MsgBox "모든 데이터가 새로고침되었습니다!", vbInformation
End Sub

Three jobs for the same workbook

Closing the month

Imagine the last-day ERP export arriving at 5 p.m. Save the CSV to the folder the queries expect, refresh the data and measures, then check the dashboard. If a separate approved workflow handles Teams or email, the finished report can go out that way. Workbook refresh by itself doesn't send it.

Comparing departments

Use the department relationship to ask how the average order compares across teams. The measure belongs with Orders_Combined.

// Average order value by department
Dept_Avg_Amount =
AVERAGEX(
    VALUES(Departments[부서명]),
    [Total_Amount]
)

// Rank the departments.
Dept_Rank =
RANKX(
    ALL(Departments[부서명]),
    [Total_Amount],
    ,
    DESC
)

Looking at the product mix

Products provides the category filter. A share measure needs to preserve the numerator's category context and remove the appropriate filter when calculating the total.

// Sales share by category
Category_Share =
DIVIDE(
    CALCULATE(
        [Total_Amount],
        ALLEXCEPT(Products, Products[카테고리])
    ),
    CALCULATE(
        [Total_Amount],
        ALL(Products)
    ),
    0
)

When the workbook doesn't behave

Excel reports an ambiguous relationship

Look for an existing active path between the same tables and duplicate keys on the lookup side. Deactivate a conflicting relationship if the model needs an alternate path. If the data truly has a many-to-many relationship, model it with a bridge table.

A measure takes minutes to refresh

If a small report takes five minutes, look at the calculation before buying a bigger machine. An iterator and a context change for every order can be a very expensive way of asking for a sum.

// Before: row-by-row calculation
Slow_Measure =
SUMX(
    Orders_Combined,
    CALCULATE(SUM(Orders_Combined[금액]))
)

// After: a direct sum
Fast_Measure =
SUM(Orders_Combined[금액])

The model runs out of memory

Remove unused columns before you load them, choose appropriate data types and avoid retaining unnecessary high-cardinality text. A large workbook may also need 64-bit Excel.


Taking the model into Power BI

A Power BI deployment can add scheduled refresh, a shared report, mobile views, anomaly detection and row-level access for departments. The useful work already done is the definition of the relationships and measures.


How the finished dashboard fits together

Monthly purchasing
Period | Department | Category | Refresh
Order value 45.2m | Month over month +15.3% | Added 2 | Modified 3
Monthly trend (line)            Change mix (doughnut)
Departments (columns)           Top five products (table)
Order detail with drill-down

What the time saving looked like

In my example the manual report took three to four hours. A working model brought a routine refresh down to around thirty seconds and let someone explore the figures without rebuilding the sheet. That removes opportunities for copying errors, though the input and model still need checking. At twenty hours saved a month, the annual saving is 240 hours. Value those at ₩50,000 an hour and the illustration comes to ₩12 million against a two-hour setup, more than a hundred times the setup time over a year.


What I'd keep from this exercise

Prepare the rows once, relate them where the keys are reliable, and define each measure in one place. Now the person asking why a department's orders changed can move from the monthly total to the underlying rows themselves. Next month has become another refresh.


Open the workbook

Download the Power Pivot example, one XLSX in a ZIP. Use the workbook alongside the model, measure and dashboard steps above.


For the matching logic that feeds the dashboard, see Comparing two tables with Power Query.


© 2025 B.J.T. · Boundless Journey of Thought

The companion exercise