Power Bi Training Courses London UK

Testing table functions in measures

DAX is a formula language used for creating calculated columns, measures, and tables. It is a common misconception that the table functions in DAX are used to create calculated tables only. However, this is not true. In this blog, you will learn how to use table functions in measures.

 To test the table functions in measures:

  1. Right click on All Measures in the Fields.
  2. Click on New measure.

Measure tools open.

  1. Type the following formula in the formula bar and press Enter.Testing table functions

In this Expression:

  • You have used VALUES() on the Product table which returns all the rows.
  • VALUES() is encapsulated in COUNTROWS() function to return the number of rows.
  1. Click on the card visual in the visualization pane.
  2. Drag and drop Testing Table functions in a Measure (CM) from the All Measures table to the Fields.Testing All Measures table
  3. Click on the matrix visual in the visualization pane.
  4. Drag and drop Category from the Products table to the rows.
  5. Drag and drop Testing Table functions in a Measure (CM) from the All Measures table to the Values.Category

Notice that as the filter context from the rows propagates, the values for the Testing Table functions in a Measure (CM) change. The total of the card visual and matrix is same.

Let’s now slightly alter the DAX expression and add column to the VALUES() parameter.

  1. Click on Testing Table functions in a Measure (CM) in All Measures table.

Measure tools open.

  1. Replace Product table with Product Column so that your expression looks like the image below.Count-Rows

In this expression:

  • The VALUES() function finds the distinct values of products.
  • The VALUES() forms a virtual table and COUNTROWS() counts the number of rows in the virtual table.distinct values of products
  1. Click on Testing Table functions in a Measure (CM) in All Measures table.

Measure tools open.

  1. Replace with Subcategory column so that your expression looks like the image below.Replace with Subcategory

In this expression:

  • The VALUES() function finds the distinct values of Product Subcategory.
  • The VALUES() forms a virtual table and COUNTROWS() counts the number of rows in the virtual table.

Notice that only 37 categories exist. As the filter context comes into play in the Matrix, it is seen that Accessories have the greatest number of subcategories and Bikes have the least.Category-List

  1. Click on Testing Table functions in a Measure (CM) in All Measures table.

Measure tools open.

  1. Replace the VALUES() function with ALL() so that your expression looks like the image below.Replace with Subcategory

In this expression:

  • The ALL() function finds the distinct values of Products Subcategory.
  • The ALL() forms a virtual table and COUNTROWS() counts the number of rows in the virtual table.

Notice the change in values. ALL() ignores the filter context so the same value is shown for all categories and on the card. This is the total number of subcategories in the data.Categories

  1. Click on Testing Table functions in a Measure (CM) in All Measures table.

Measure tools open.

  1. Replace the Subcategory column with the Category column so that your expression looks like the image below.

In this expression:

  • The ALL() function finds the distinct values of Products Category.
  • The ALL() forms a virtual table and COUNTROWS() counts the number of rows in the virtual table.

Notice that only 4 categories exist. Filter context is ignored by ALL().

Conclusion:

DAX is a formula language developed by Microsoft to help data analysts enrich their data model by performing calculations on the top of data model. DAX can be used to create calculated columns, measures, and tables. It is a formula language, and these formulas are used to perform calculations. In this blog post, table functions in DAX are used to calculate measures.

Are you looking for an instructor-led Power BI or Power Apps training in Australia? We provide classroom as well as online live trainings for the following courses:

Leave a Reply

Your email address will not be published. Required fields are marked *

DAX is a formula language used for creating calculated columns, measures, and tables. It is a common misconception that the table functions in DAX are used to create calculated tables only. However, this is not true. In this blog, you will learn how to use table functions in measures.

 To test the table functions in measures:

  1. Right click on All Measures in the Fields.
  2. Click on New measure.

Measure tools open.

  1. Type the following formula in the formula bar and press Enter.Testing table functions

In this Expression:

  1. Click on the card visual in the visualization pane.
  2. Drag and drop Testing Table functions in a Measure (CM) from the All Measures table to the Fields.Testing All Measures table
  3. Click on the matrix visual in the visualization pane.
  4. Drag and drop Category from the Products table to the rows.
  5. Drag and drop Testing Table functions in a Measure (CM) from the All Measures table to the Values.Category

Notice that as the filter context from the rows propagates, the values for the Testing Table functions in a Measure (CM) change. The total of the card visual and matrix is same.

Let’s now slightly alter the DAX expression and add column to the VALUES() parameter.

  1. Click on Testing Table functions in a Measure (CM) in All Measures table.

Measure tools open.

  1. Replace Product table with Product Column so that your expression looks like the image below.Count-Rows

In this expression:

  1. Click on Testing Table functions in a Measure (CM) in All Measures table.

Measure tools open.

  1. Replace with Subcategory column so that your expression looks like the image below.Replace with Subcategory

In this expression:

Notice that only 37 categories exist. As the filter context comes into play in the Matrix, it is seen that Accessories have the greatest number of subcategories and Bikes have the least.Category-List

  1. Click on Testing Table functions in a Measure (CM) in All Measures table.

Measure tools open.

  1. Replace the VALUES() function with ALL() so that your expression looks like the image below.Replace with Subcategory

In this expression:

Notice the change in values. ALL() ignores the filter context so the same value is shown for all categories and on the card. This is the total number of subcategories in the data.Categories

  1. Click on Testing Table functions in a Measure (CM) in All Measures table.

Measure tools open.

  1. Replace the Subcategory column with the Category column so that your expression looks like the image below.

In this expression:

Notice that only 4 categories exist. Filter context is ignored by ALL().

Conclusion:

DAX is a formula language developed by Microsoft to help data analysts enrich their data model by performing calculations on the top of data model. DAX can be used to create calculated columns, measures, and tables. It is a formula language, and these formulas are used to perform calculations. In this blog post, table functions in DAX are used to calculate measures.

Are you looking for an instructor-led Power BI or Power Apps training in Australia? We provide classroom as well as online live trainings for the following courses:

Contact Us

Kindly submit your details and a training consultant will contact you shortly.