Table manipulation functions

Intermediate DAX in Power BI

Maarten Van den Broeck

Content Developer at DataCamp

Table manipulation functions overview

Previously seen functions
DISTINCT(<table> | <table>)

Removes duplicate rows from a table or values from a column

SELECTCOLUMNS(<table>, <name>, <expression>)

Returns the selected columns from another table as a new table

New functions
ADDCOLUMNS(<table>, <name>, <expression>)

Returns the input table appended with the selected columns from another table

SUMMARIZE(<table>,
          <groupBy_columnName>,
          <name>,
          <expression>)

Returns a summary table for the requested totals over a set of groups

Intermediate DAX in Power BI

ADDCOLUMNS()

ADDCOLUMNS(<table>, <name>, <expression>) 

Returns the input table appended with the selected columns from another table

ADDCOLUMNS(Fact_table,
           "Profit",
           Revenue - Costs)
Intermediate DAX in Power BI

ADDCOLUMNS()

ADDCOLUMNS(<table>, <name>, <expression>) 

Returns the input table appended with the selected columns from another table

ADDCOLUMNS(Fact_table,
           "Profit",
           Revenue - Costs) 
Revenue Costs Profit
100 25 75
150 25 125
Intermediate DAX in Power BI

ADDCOLUMNS()

ADDCOLUMNS(<table>, <name>, <expression>) 

Returns the input table appended with the selected columns from another table

ADDCOLUMNS(Fact_table,
           "Profit",
           Revenue - Costs) 
Revenue Costs Profit
100 25 75
150 25 125
SELECTCOLUMNS(<table>, <name>, <expression>)

Returns the selected columns from another table as a new table

SELECTCOLUMNS(Fact_table,
              "Profit",
              Revenue - Costs) 
Profit
75
125
Intermediate DAX in Power BI

SUMMARIZE()

SUMMARIZE(<table>,
          <groupBy_columnName>,
          <name>,
          <expression>)

Returns a summary table for the requested totals over a set of groups

Intermediate DAX in Power BI

SUMMARIZE()

SUMMARIZE(<table>,
          <groupBy_columnName>,
          <name>,
          <expression>)

Returns a summary table for the requested totals over a set of groups

SUMMARIZE(Amounts,

Amounts[Year], Amounts[Category],
"Total Amount", SUM(Amounts[Amount]))
Year Category Amount
2019 Tickets 50
2019 Postcards 500
2020 Tickets 200
2020 Tickets 400
Intermediate DAX in Power BI

SUMMARIZE()

SUMMARIZE(<table>,
          <groupBy_columnName>,
          <name>,
          <expression>)

Returns a summary table for the requested totals over a set of groups

SUMMARIZE(Amounts,

Amounts[Year], Amounts[Category],
"Total Amount", SUM(Amounts[Amount]))
Year Category Amount
2019 Tickets 50
2019 Postcards 500
2020 Tickets 200
2020 Tickets 400

$$

Year Category Total Amount
2019 Tickets 50
2019 Postcards 500
2020 Tickets 600
Intermediate DAX in Power BI

SUMMARIZE() best practices

  • Created columns of SUMMARIZE() can give unexpected results based on context

$$

SUMMARIZE(Amounts,
          Amounts[Year],
          Amounts[Category]),
          "Total Amount",
          SUM(Amounts[Amount])
  • Best practice is to wrap ADDCOLUMNS() around SUMMARIZE() when creating new columns
ADDCOLUMNS(
    SUMMARIZE(Amounts,
               Amounts[Year],
               Amounts[Category]),
    "Total Amount",
    SUM(Amounts[Amount])
)
Intermediate DAX in Power BI

Let's practice!

Intermediate DAX in Power BI

Preparing Video For Download...