0% found this document useful (0 votes)
11 views10 pages

Power BI Table Operations

This document is a comprehensive cheatsheet for Power BI table operations, detailing various functions for table creation, transformation, filtering, sorting, grouping, merging, and text operations. It includes syntax examples for creating tables from different data sources, manipulating table structures, and performing data analysis tasks. The document serves as a quick reference guide for users working with Power BI to efficiently manage and analyze data tables.

Uploaded by

vamsitarak55
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views10 pages

Power BI Table Operations

This document is a comprehensive cheatsheet for Power BI table operations, detailing various functions for table creation, transformation, filtering, sorting, grouping, merging, and text operations. It includes syntax examples for creating tables from different data sources, manipulating table structures, and performing data analysis tasks. The document serves as a quick reference guide for users working with Power BI to efficiently manage and analyze data tables.

Uploaded by

vamsitarak55
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

# [ Power BI Table Operations ] [ cheatsheet ]

Table Creation and Conversion:

● #table({"Column1", "Column2"}, {{"Value1", 1}, {"Value2", 2}}): Create a


table with specified column names and values.
● Excel.Workbook(File.Contents("FilePath")): Load an Excel workbook into a
table.
● Csv.Document(File.Contents("FilePath")): Load a CSV file into a table.
● Json.Document(File.Contents("FilePath")): Load a JSON file into a table.
● Xml.Tables(File.Contents("FilePath")): Load an XML file into a table.
● Table.FromList({1, 2, 3}, Splitter.SplitByNothing(), null, null,
ExtraValues.Error): Create a table from a list.
● Table.FromRows({[Name = "John", Age = 30], [Name = "Jane", Age = 25]}):
Create a table from a list of records.
● Table.FromValue("Value"): Create a table from a single value.
● Table.ToRows(Table): Convert a table to a list of rows.
● Table.ToList(Table): Convert a table to a list of values.
● Table.ToRecords(Table): Convert a table to a list of records.

Table Information:

● Table.ColumnNames(Table): Get a list of column names in a table.


● Table.ColumnCount(Table): Get the number of columns in a table.
● Table.RowCount(Table): Get the number of rows in a table.
● Table.IsEmpty(Table): Check if a table is empty.
● Table.Schema(Table): Get the schema of a table.
● Table.Profile(Table): Get a profile of a table with column statistics.

Table Transformation:

● Table.AddColumn(Table, "NewColumn", Expression): Add a new column to a


table based on an expression.
● Table.RemoveColumns(Table, {"Column1", "Column2"}): Remove specified
columns from a table.
● Table.RenameColumns(Table, {{"OldName", "NewName"}, {"OldName2",
"NewName2"}}): Rename columns in a table.
● Table.ReorderColumns(Table, {"Column1", "Column2"}): Reorder columns in a
table.

By: Waleed Mousa


● Table.TransformColumns(Table, {{"Column", Function}, {"Column2",
Function2}}): Apply transformations to specified columns in a table.
● Table.TransformColumnTypes(Table, {{"Column", type}, {"Column2", type}}):
Change the data types of specified columns in a table.
● Table.AddIndexColumn(Table, "IndexColumn", 1, 1): Add an index column to
a table.
● Table.PromoteHeaders(Table): Promote the first row of a table as column
headers.
● Table.DemoteHeaders(Table): Demote the column headers of a table to the
first row.
● Table.Transpose(Table): Transpose the rows and columns of a table.

Row Filtering and Sorting:

● Table.SelectRows(Table, each [Column] > 10): Filter rows based on a


condition.
● Table.RemoveRows(Table, each [Column] > 10): Remove rows based on a
condition.
● Table.Distinct(Table): Remove duplicate rows from a table.
● Table.RemoveMatchingRows(Table1, Table2, {"Column"}): Remove rows from
Table1 that match rows in Table2 based on a column.
● Table.KeepMatchingRows(Table1, Table2, {"Column"}): Keep only the rows
from Table1 that match rows in Table2 based on a column.
● Table.Sort(Table, {{"Column", Order.Ascending}, {"Column2",
Order.Descending}}): Sort a table based on specified columns and order.
● Table.TopN(Table, 10, {{"Column", Order.Descending}}): Get the top N rows
from a table based on a column.
● Table.FirstN(Table, 10): Get the first N rows from a table.
● Table.Range(Table, 5, 10): Get a range of rows from a table.
● Table.Sample(Table, 10, 123): Get a random sample of rows from a table.

Grouping and Aggregation:

● Table.Group(Table, {"Column"}, {{"AggColumn", each List.Sum([Column]),


type number}}): Group a table by a column and perform aggregations.
● Table.GroupBy(Table, {"Column"}, {{"Count", each Table.RowCount(_),
Int64.Type}}): Group a table by a column and count the number of rows in
each group.

By: Waleed Mousa


● Table.AggregateTableColumn(Table, "ColumnToAggregate", {{"Sum", each
List.Sum(_), type number}}): Aggregate values in a column of a nested
table.
● Table.Pivot(Table, {"ColumnToPivot"}, "ColumnToAggregate",
"ColumnForValues"): Pivot a table based on a column.
● Table.Unpivot(Table, {"ColumnToUnpivot1", "ColumnToUnpivot2"},
"AttributeColumn", "ValueColumn"): Unpivot columns of a table into
attribute-value pairs.

Merging and Joining Tables:

● Table.NestedJoin(Table1, {"JoinColumn"}, Table2, {"JoinColumn"},


"NewColumn", JoinKind.Inner): Perform an inner join between two tables
based on a column.
● Table.NestedJoin(Table1, {"JoinColumn"}, Table2, {"JoinColumn"},
"NewColumn", JoinKind.LeftOuter): Perform a left outer join between two
tables based on a column.
● Table.Join(Table1, "JoinColumn", Table2, "JoinColumn", JoinKind.Inner):
Perform an inner join between two tables based on a column.
● Table.Join(Table1, "JoinColumn", Table2, "JoinColumn",
JoinKind.LeftOuter): Perform a left outer join between two tables based
on a column.
● Table.Join(Table1, "JoinColumn", Table2, "JoinColumn",
JoinKind.RightOuter): Perform a right outer join between two tables
based on a column.
● Table.Join(Table1, "JoinColumn", Table2, "JoinColumn",
JoinKind.FullOuter): Perform a full outer join between two tables based
on a column.
● Table.Join(Table1, "JoinColumn", Table2, "JoinColumn",
JoinKind.LeftAnti): Perform a left anti join between two tables based on
a column.
● Table.Join(Table1, "JoinColumn", Table2, "JoinColumn",
JoinKind.RightAnti): Perform a right anti join between two tables based
on a column.
● Table.AddJoinColumn(Table1, "Table2", Table2, {"JoinColumn",
"JoinColumn"}, "NewColumn"): Add a join column to Table1 based on
matching values from Table2.
● Table.Combine({Table1, Table2, Table3}): Combine multiple tables
vertically.

By: Waleed Mousa


Table Splitting:

● Table.SplitColumn(Table, "ColumnToSplit",
Splitter.SplitTextByDelimiter(","), {"NewColumn1", "NewColumn2"}): Split
a column into multiple columns based on a delimiter.
● Table.SplitColumn(Table, "ColumnToSplit",
Splitter.SplitTextByPositions({0, 5}, true), {"NewColumn1",
"NewColumn2"}): Split a column into multiple columns based on positions.
● Table.SplitColumn(Table, "ColumnToSplit",
Splitter.SplitTextByRepeatedLengths(5), {"NewColumn1", "NewColumn2"}):
Split a column into multiple columns based on repeated lengths.
● Table.SplitColumn(Table, "ColumnToSplit", Splitter.SplitTextByRanges({{0,
2}, {2, 4}}), {"NewColumn1", "NewColumn2"}): Split a column into multiple
columns based on ranges.
● Table.SplitColumn(Table, "ColumnToSplit",
Splitter.SplitTextByWhitespace(), {"NewColumn1", "NewColumn2"}): Split a
column into multiple columns based on whitespace.
● Table.SplitColumn(Table, "ColumnToSplit",
Splitter.SplitTextByCharacterTransition({"a".."z"}, {"A".."Z"}),
{"NewColumn1", "NewColumn2"}): Split a column into multiple columns
based on character transition.
● Table.SplitColumn(Table, "ColumnToSplit",
Splitter.SplitTextByEachDelimiter({",", ";"}, QuoteStyle.None, true),
{"NewColumn1", "NewColumn2"}): Split a column into multiple columns
based on each delimiter.
● Table.SplitColumn(Table, "ColumnToSplit", Splitter.SplitTextByLengths({5,
10}, true), {"NewColumn1", "NewColumn2"}): Split a column into multiple
columns based on specified lengths.
● Table.SplitColumn(Table, "ColumnToSplit",
Splitter.SplitTextByNumbers({"NewColumn1", "NewColumn2"}, true)): Split a
column into multiple columns based on numbers.
● Table.SplitColumn(Table, "ColumnToSplit",
Splitter.SplitTextByLetters({"NewColumn1", "NewColumn2"}, true)): Split a
column into multiple columns based on letters.

Table Filtering:

● Table.SelectRows(Table, each Text.Contains([Column], "Keyword")): Filter


rows based on a text condition.
● Table.SelectRows(Table, each [Column] >= #date(2022, 1, 1)): Filter rows
based on a date condition.
By: Waleed Mousa
● Table.SelectRows(Table, each [Column1] = "Value" and [Column2] > 10):
Filter rows based on multiple conditions.
● Table.SelectRows(Table, each List.Contains({"Value1", "Value2"},
[Column])): Filter rows based on a list of values.
● Table.SelectRows(Table, each [Column] = null): Filter rows where a column
is null.
● Table.SelectRows(Table, each [Column] <> null): Filter rows where a
column is not null.
● Table.SelectRows(Table, each Text.StartsWith([Column], "Prefix")): Filter
rows where a column starts with a specific prefix.
● Table.SelectRows(Table, each Text.EndsWith([Column], "Suffix")): Filter
rows where a column ends with a specific suffix.
● Table.SelectRows(Table, each Number.IsEven([Column])): Filter rows where
a column contains even numbers.
● Table.SelectRows(Table, each Number.IsOdd([Column])): Filter rows where a
column contains odd numbers.

Table Transformation Functions:

● Table.TransformRows(Table, (row) => Record.TransformFields(row,


{"Column", Text.Upper})): Apply a transformation function to each row of
a table.
● Table.TransformColumns(Table, {{"Column", Text.Upper}}): Apply a
transformation function to a specific column of a table.
● Table.TransformColumnTypes(Table, {{"Column", type number}}): Change the
data type of a specific column in a table.
● Table.TransformColumns(Table, {{"Column", each _ * 2}}): Apply a math
operation to a specific column of a table.
● Table.TransformColumns(Table, {{"Column", each Text.PadStart(_, 5,
"0")}}): Pad values in a column with leading characters.
● Table.TransformColumns(Table, {{"Column", each Text.PadEnd(_, 5, "0")}}):
Pad values in a column with trailing characters.
● Table.TransformColumns(Table, {{"Column", each Text.Replace(_,
"OldValue", "NewValue")}}): Replace values in a column.
● Table.TransformColumns(Table, {{"Column", each Text.Remove(_,
{"0".."9"})}}): Remove specific characters from values in a column.
● Table.TransformColumns(Table, {{"Column", each Text.Trim(_)}}): Trim
whitespace from values in a column.
● Table.TransformColumns(Table, {{"Column", each Date.AddDays(_, 1)}}): Add
days to dates in a column.

By: Waleed Mousa


Date and Time Operations:

● Table.AddColumn(Table, "NewColumn", each Date.Year([DateColumn])):


Extract the year from a date column.
● Table.AddColumn(Table, "NewColumn", each Date.Month([DateColumn])):
Extract the month from a date column.
● Table.AddColumn(Table, "NewColumn", each Date.Day([DateColumn])): Extract
the day from a date column.
● Table.AddColumn(Table, "NewColumn", each Time.Hour([TimeColumn])):
Extract the hour from a time column.
● Table.AddColumn(Table, "NewColumn", each Time.Minute([TimeColumn])):
Extract the minute from a time column.
● Table.AddColumn(Table, "NewColumn", each Time.Second([TimeColumn])):
Extract the second from a time column.
● Table.AddColumn(Table, "NewColumn", each Date.DayOfWeek([DateColumn])):
Extract the day of the week from a date column.
● Table.AddColumn(Table, "NewColumn", each Date.DayOfYear([DateColumn])):
Extract the day of the year from a date column.
● Table.AddColumn(Table, "NewColumn", each Date.WeekOfYear([DateColumn])):
Extract the week of the year from a date column.
● Table.AddColumn(Table, "NewColumn", each
Date.QuarterOfYear([DateColumn])): Extract the quarter of the year from a
date column.
● Table.AddColumn(Table, "NewColumn", each Date.StartOfDay([DateColumn])):
Get the start of the day from a date column.
● Table.AddColumn(Table, "NewColumn", each Date.EndOfDay([DateColumn])):
Get the end of the day from a date column.
● Table.AddColumn(Table, "NewColumn", each Date.StartOfWeek([DateColumn])):
Get the start of the week from a date column.
● Table.AddColumn(Table, "NewColumn", each Date.EndOfWeek([DateColumn])):
Get the end of the week from a date column.
● Table.AddColumn(Table, "NewColumn", each
Date.StartOfMonth([DateColumn])): Get the start of the month from a date
column.
● Table.AddColumn(Table, "NewColumn", each Date.EndOfMonth([DateColumn])):
Get the end of the month from a date column.
● Table.AddColumn(Table, "NewColumn", each
Date.StartOfQuarter([DateColumn])): Get the start of the quarter from a
date column.

By: Waleed Mousa


● Table.AddColumn(Table, "NewColumn", each
Date.EndOfQuarter([DateColumn])): Get the end of the quarter from a date
column.
● Table.AddColumn(Table, "NewColumn", each
Date.StartOfYear([DateColumn])): Get the start of the year from a date
column.
● Table.AddColumn(Table, "NewColumn", each Date.EndOfYear([DateColumn]))`:
Get the end of the year from a date column.

Text Operations:

● Table.AddColumn(Table, "NewColumn", each Text.Length([TextColumn])):


Calculate the length of values in a text column.
● Table.AddColumn(Table, "NewColumn", each Text.Upper([TextColumn])):
Convert values in a text column to uppercase.
● Table.AddColumn(Table, "NewColumn", each Text.Lower([TextColumn])):
Convert values in a text column to lowercase.
● Table.AddColumn(Table, "NewColumn", each Text.Proper([TextColumn])):
Convert values in a text column to proper case.
● Table.AddColumn(Table, "NewColumn", each Text.Trim([TextColumn])): Trim
whitespace from values in a text column.
● Table.AddColumn(Table, "NewColumn", each Text.TrimStart([TextColumn])):
Trim leading whitespace from values in a text column.
● Table.AddColumn(Table, "NewColumn", each Text.TrimEnd([TextColumn])):
Trim trailing whitespace from values in a text column.
● Table.AddColumn(Table, "NewColumn", each Text.Replace([TextColumn],
"OldValue", "NewValue")): Replace specific values in a text column.
● Table.AddColumn(Table, "NewColumn", each Text.Remove([TextColumn],
{"a".."z", "A".."Z"})): Remove specific characters from values in a text
column.
● Table.AddColumn(Table, "NewColumn", each
Text.Combine(List.Transform(Text.Split([TextColumn], " "), each
Text.Left(_, 1)))): Extract the first letter of each word in a text
column.

Number Operations:

● Table.AddColumn(Table, "NewColumn", each Number.Round([NumberColumn],


2)): Round values in a number column to a specified number of decimal
places.

By: Waleed Mousa


● Table.AddColumn(Table, "NewColumn", each Number.Abs([NumberColumn])):
Calculate the absolute value of numbers in a column.
● Table.AddColumn(Table, "NewColumn", each Number.Sign([NumberColumn])):
Determine the sign of numbers in a column (-1, 0, or 1).
● Table.AddColumn(Table, "NewColumn", each Number.Sqrt([NumberColumn])):
Calculate the square root of numbers in a column.
● Table.AddColumn(Table, "NewColumn", each Number.Power([NumberColumn],
2)): Raise numbers in a column to a specified power.
● Table.AddColumn(Table, "NewColumn", each Number.Log([NumberColumn])):
Calculate the natural logarithm of numbers in a column.
● Table.AddColumn(Table, "NewColumn", each Number.Log10([NumberColumn])):
Calculate the base-10 logarithm of numbers in a column.
● Table.AddColumn(Table, "NewColumn", each Number.Exp([NumberColumn])):
Calculate the exponential of numbers in a column.
● Table.AddColumn(Table, "NewColumn", each
Number.Factorial([NumberColumn])): Calculate the factorial of numbers in
a column.
● Table.AddColumn(Table, "NewColumn", each
Number.Permutations([NumberColumn], 2)): Calculate the number of
permutations for numbers in a column.

Conditional Operations:

● Table.AddColumn(Table, "NewColumn", each if [Column1] > 10 then "High"


else "Low"): Add a conditional column based on a simple condition.
● Table.AddColumn(Table, "NewColumn", each if [Column1] > 10 then "High"
else if [Column1] > 5 then "Medium" else "Low"): Add a conditional column
based on multiple conditions.
● Table.AddColumn(Table, "NewColumn", each case [Column1] when 1 then "A"
when 2 then "B" else "C"): Add a conditional column using a case
statement.
● Table.SelectRows(Table, each if [Column1] = "Value" then true else
false): Filter rows based on a conditional expression.
● Table.ReplaceValue(Table, each if _ = "OldValue" then "NewValue" else _,
Replacer.ReplaceValue, {"Column1"}): Replace values in a column based on
a condition.
● Table.TransformColumns(Table, {{"Column1", each if _ > 10 then _ else
null}}): Transform values in a column based on a condition.

By: Waleed Mousa


● Table.AddColumn(Table, "NewColumn", each try Number.FromText([Column1])
otherwise null): Handle errors and replace with a default value using a
try-otherwise block.
● Table.AddColumn(Table, "NewColumn", each if Table.ColumnNames(Table){0} =
"Column1" then [Column1] else null): Add a conditional column based on
the existence of a specific column.
● Table.AddColumn(Table, "NewColumn", each if List.Contains({"Value1",
"Value2"}, [Column1]) then "Match" else "No Match"): Add a conditional
column based on a list of values.
● Table.AddColumn(Table, "NewColumn", each if Text.StartsWith([Column1],
"Prefix") then "Starts with Prefix" else "Doesn't Start with Prefix"):
Add a conditional column based on a text condition.

List Operations:

● Table.AddColumn(Table, "NewColumn", each List.Sum([ListColumn])):


Calculate the sum of values in a list column.
● Table.AddColumn(Table, "NewColumn", each List.Average([ListColumn])):
Calculate the average of values in a list column.
● Table.AddColumn(Table, "NewColumn", each List.Min([ListColumn])): Find
the minimum value in a list column.
● Table.AddColumn(Table, "NewColumn", each List.Max([ListColumn])): Find
the maximum value in a list column.
● Table.AddColumn(Table, "NewColumn", each List.Count([ListColumn])): Count
the number of items in a list column.
● Table.AddColumn(Table, "NewColumn", each List.Distinct([ListColumn])):
Get distinct values from a list column.
● Table.AddColumn(Table, "NewColumn", each List.First([ListColumn])): Get
the first item from a list column.
● Table.AddColumn(Table, "NewColumn", each List.Last([ListColumn])): Get
the last item from a list column.
● Table.AddColumn(Table, "NewColumn", each List.Combine([ListColumn1],
[ListColumn2])): Combine multiple list columns into a single list
column.
● Table.AddColumn(Table, "NewColumn", each List.Transform([ListColumn],
each _ * 2)): Apply a transformation function to each item in a list
column.

Record Operations:

By: Waleed Mousa


● Table.AddColumn(Table, "NewColumn", each Record.Field([RecordColumn],
"FieldName")): Extract a specific field from a record column.
● Table.AddColumn(Table, "NewColumn", each
Record.FieldNames([RecordColumn])): Get the field names of a record
column.
● Table.AddColumn(Table, "NewColumn", each Record.HasFields([RecordColumn],
{"Field1", "Field2"})): Check if a record column has specific fields.
● Table.AddColumn(Table, "NewColumn", each
Record.RemoveFields([RecordColumn], {"Field1", "Field2"})): Remove
specific fields from a record column.
● Table.AddColumn(Table, "NewColumn", each
Record.RenameFields([RecordColumn], {"OldField", "NewField"})): Rename
fields in a record column.
● Table.AddColumn(Table, "NewColumn", each
Record.TransformFields([RecordColumn], {"Field1", each _ * 2})):
Transform values of specific fields in a record column.
● Table.AddColumn(Table, "NewColumn", each Record.Combine([RecordColumn1],
[RecordColumn2])): Combine multiple record columns into a single record
column.
● Table.ExpandRecordColumn(Table, "RecordColumn", {"Field1", "Field2"},
{"Field1", "Field2"}): Expand a record column into separate columns.
● Table.AddColumn(Table, "NewColumn", each
Record.FieldCount([RecordColumn])): Count the number of fields in a record
column.
● Table.AddColumn(Table, "NewColumn", each Record.ToTable([RecordColumn])):
Convert a record column to a table.

By: Waleed Mousa

You might also like