Table Functions () | Power BI || Belayet Hossain

Table Functions () | Power BI || Belayet Hossain

In Power BI, table functions are DAX functions that return a table as their output rather than a single value. These functions are often used in conjunction with other DAX functions to perform operations on tables, filter data, or summarize data.

They play a crucial role in defining relationships, creating calculated tables, and shaping the data before visualization.

|

Let's break down the table functions in Power BI with examples for each function in an easy-to-follow structure:


?? 1. VALUES()

  • Purpose: Returns a one-column table that contains the distinct values from the specified column.
  • Use: Typically used to retrieve unique values from a column.
  • Syntax: ????????????(??????????[????????????])

Example:

  • Scenario: You want to get the list of products sold.

DAX: ????????????(????????????[??????????????])

  • Explanation: ????????????() returns all distinct product names, similar to DISTINCT(), but VALUES() also respects row-level security and filters.
  • Relevant DAX: ????????????????(), ??????()


??2. DISTINCT()

  • Purpose: Returns a table with distinct values from a column.
  • Use: When you want to remove duplicates from a column or table.
  • Syntax: ????????????????(??????????[????????????])

Example:

  • Scenario: You want to know which distinct products were ordered.

DAX: ????????????????(????????????[??????????????])

  • Explanation: ????????????????() is functionally similar to VALUES(), but VALUES() can return a blank if there are no rows.
  • Relevant DAX: VALUES()


??3. ALL()

  • Purpose: Removes filters from the specified table or column.
  • Use: To ignore filters in calculations.
  • Syntax: ??????(??????????)

Example:

  • Scenario: To calculate a total ignoring all filters on the Product column.

DAX: ??????(????????????[??????????????])


  • Explanation: ??????() is useful in measures where you want to ignore filters and get the entire dataset.
  • Relevant DAX: REMOVEFILTERS()


??4. SUMMARIZECOLUMNS()

  • Purpose: Creates a summary table for the requested totals over a set of groups.
  • Use: Used for grouping data and calculating aggregated results.
  • Syntax: ????????????????????????????????(??????????[??????????????_????????????], ??????????[??????????????_????????????])

Example:

  • Scenario: To summarize total quantities by product.

DAX: ????????????????????????????????(????????????[??????????????], "??????????????????????????", ??????(????????????[????????????????]))


  • Explanation: SUMMARIZECOLUMNS() is an efficient way to aggregate data.
  • Relevant DAX: SUMMARIZE(), GROUPBY()


??5. ADDCOLUMNS()

  • Purpose: Adds calculated columns to a table.
  • Use: To create new columns in a table based on calculations.
  • Syntax: ????????????????????(??????????, "??????_????????????", ????????????????????)

Example:

  • Scenario: Adding a column to calculate the total price for each product.

DAX: ????????????????????(????????????, "????????????????????", ????????????[????????????????] * 10)


  • Explanation: ????????????????????() is used to add additional calculated data to an existing table.
  • Relevant DAX: ??????????????????????????(), ??????????????????()


??6. SELECTCOLUMNS()

  • Purpose: Creates a new table by selecting specific columns from an existing table.
  • Use: Useful for picking only relevant columns from a table.
  • Syntax: ??????????????????????????(??????????, "??????_????????????1", ??????????[????????????1], "??????_????????????2", ??????????[????????????2])

Example:

  • Scenario: To create a table with only product and quantity columns.

DAX: SELECTCOLUMNS(Orders, "Product", Orders[Product], "Quantity", Orders[Quantity])


  • Explanation: ??????????????????????????() allows for column-specific selection and renaming.
  • Relevant DAX: ????????????????????() , ??????????????????()


??7. TOPN()

  • Purpose: Returns the top N rows from a table based on a given expression.
  • Use: To get the top records based on a metric.
  • Syntax: TOPN(N, Table, OrderBy_Column, Order_Direction)

Example:

  • Scenario: You want the product with the highest quantity sold.

DAX: TOPN(1, Orders, Orders[Quantity], DESC)


  • Explanation: ????????() is ideal for filtering the highest or lowest values.
  • Relevant DAX: RANKX()


??8. CROSSJOIN()

  • Purpose: Returns a Cartesian product of two tables.
  • Use: To join every row from the first table with every row from the second.
  • Syntax: CROSSJOIN(Table1, Table2)

Example:

  • Scenario: To combine all products with all quantities.

DAX: CROSSJOIN(Products, Quantities)

  • Explanation: ??????????????????() returns every combination of rows from both tables.
  • Relevant DAX: UNION()


??9. GENERATESERIES()

  • Purpose: Returns a single-column table of values from start to end.
  • Use: Useful for generating a sequence of numbers.
  • Syntax: GENERATESERIES(Start, End, Increment)

Example:

  • Scenario: To generate a list of numbers from 1 to 5.

DAX: GENERATESERIES(1, 5, 1)


  • Explanation: ????????????????????????????() creates a sequence of numbers within a range.
  • Relevant DAX: SEQUENCE()


??10. RANKX()

  • Purpose: Returns the rank of a value in a list of values.
  • Use: To assign ranks to rows based on a metric.
  • Syntax:

Example: RANKX(Table, Expression)

  • Scenario: You want to rank products based on quantity sold.

DAX: RANKX(Orders, Orders[Quantity])


  • Explanation: ??????????() assigns a rank based on an expression for each row.

  • Relevant DAX: TOPN()


??11. LOOKUPVALUE()

  • Purpose: Returns the value from a column for the row that meets specified criteria.
  • Use: Used to look up values from another table or column.
  • Syntax:

Example: LOOKUPVALUE(Table[Return_Column], Table[Search_Column], Value)

  • Scenario:

DAX: LOOKUPVALUE(Prices[Price], Prices[Product], "Apple")

  • Explanation: ??????????????????????() allows fetching data from another column based on a match.
  • Relevant DAX: RELATED()


??12. CONCATENATEX()

  • Purpose: Concatenates the values of a column with a delimiter.
  • Use: To combine text values from multiple rows into one string.
  • Syntax: CONCATENATEX(Table, Table[Column], Delimiter)

Example:

  • Scenario: To create a list of all products ordered.

DAX: CONCATENATEX(Orders, Orders[Product], ", ")

  • Explanation: ????????????????????????() combines multiple values into a single text string, separated by a delimiter.
  • Relevant DAX: TEXT()


??Table Functions and Context:

  • Filter Context: Many table functions can be influenced by filter context, meaning the data returned depends on the current filters applied in the report.
  • Row Context: Functions like ADDCOLUMNS() operate within row context, where calculations are applied row by row.


??Practical Scenarios:

  • Creating Calculated Tables: Use table functions to define new tables based on existing data, which can be referenced in visuals or other DAX expressions.
  • Filtering Data: Functions like VALUES(), DISTINCT(), and ALL() help filter data dynamically for measures and calculated columns.
  • Summarizing Data: Functions such as SUMMARIZECOLUMNS() are useful when you want to group data and compute aggregations, similar to a SQL GROUP BY


#tablefunction #powerbi


要查看或添加评论,请登录

社区洞察

其他会员也浏览了