Table.Pivot Function in Power Query

The Table.Pivot function in Power Query is used to rotate a column's unique values into separate columns—each acting like a field in a new table layout.

Syntax

Table.Pivot(
  table as table,
  pivotValues as list,
  attributeColumn as text,
  valueColumn as text,
  optional aggregationFunction as nullable function
) as table     

The function has the following parameters:

Example: Sum of Sales by Month

Let’s say we have sales data by region and month:

Input

RegionMonthSales
EastJan100
EastFeb120
WestJan90
WestJan60
WestFeb110

We want months ("Jan", "Feb") to become columns, with the sum of sales per region.

Power Query M

Table.Pivot(
    Table.FromRecords({
        [Region = "East", Month = "Jan", Sales = 100],
        [Region = "East", Month = "Feb", Sales = 120],
        [Region = "West", Month = "Jan", Sales = 90],
        [Region = "West", Month = "Jan", Sales = 60],
        [Region = "West", Month = "Feb", Sales = 110]
    }),
    {"Jan", "Feb"},
    "Month",
    "Sales",
    List.Sum
)     

The output of the above code is shown below:

RegionJanFeb
East100120
West150110

Example: Employee Attendance Tracker

Input Table

EmployeeDateStatus
Alice01-Apr-25Present
Alice02-Apr-25Absent
Bob01-Apr-25Present
Bob02-Apr-25Present

Goal

Pivot Date into columns to show attendance status per employee.

Power Query M

Table.Pivot(
    Table.FromRecords({
        [Employee = "Alice", Date = "01-Apr-25", Status = "Present"],
        [Employee = "Alice", Date = "02-Apr-25", Status = "Absent"],
        [Employee = "Bob", Date = "01-Apr-25", Status = "Present"],
        [Employee = "Bob", Date = "02-Apr-25", Status = "Present"]
    }),
    {"01-Apr-25", "02-Apr-25"},
    "Date",
    "Status"
)    

The output of the above code is shown below:

Employee01-Apr-2502-Apr-25
AlicePresentAbsent
BobPresentPresent

Example: Departmental Expenses by Category

Input Table

DeptCategoryAmount
HRTravel2000
HRSupplies500
FinanceTravel3000
FinanceSoftware700
HRTravel1500

Goal

Pivot Category into columns, aggregate Amount using List.Sum.

Power Query M

Table.Pivot(
    Table.FromRecords({
        [Dept = "HR", Category = "Travel", Amount = 2000],
        [Dept = "HR", Category = "Supplies", Amount = 500],
        [Dept = "Finance", Category = "Travel", Amount = 3000],
        [Dept = "Finance", Category = "Software", Amount = 700],
        [Dept = "HR", Category = "Travel", Amount = 1500]
    }),
    {"Travel", "Supplies", "Software"},
    "Category",
    "Amount",
    List.Sum
)    

The output of the above code is shown below:

DeptTravelSuppliesSoftware
HR3500500null
Finance3000null700

Tips for Using Table.Pivot