ORDERBY

How to Use the Power BI DAX function ORDERBY

In this article, we will discuss how to use the ORDERBY function in Power BI, along with some examples to help you understand its functionalities.

Syntax of ORDERBY Function

The syntax for the ORDERBY function is as follows:


ORDERBY(table, columnName1[, sortOrder1], [columnName2[, sortOrder2]], …)


The parameters for this function are as follows:

– **table**: The table that contains the data you want to sort.

– **columnName1**: The name of the column you want to sort by.

– **sortOrder1**: The order in which you want to sort the data in the first column. This parameter is optional and defaults to ascending order if not specified.

– **columnName2**: The name of the second column you want to sort by. This parameter is optional and can be repeated to sort the data by multiple columns.

– **sortOrder2**: The order in which you want to sort the data in the second column. This parameter is also optional and defaults to ascending order if not specified.

Example 1: Sorting Data by a Single Column

Suppose we have a table of sales data that contains the following columns:

– ProductName

– SalesAmount

To sort this data by the SalesAmount column in descending order, we can use the following formula:


ORDERBY(SalesData, SalesAmount, DESC)


This formula sorts the SalesData table by the SalesAmount column in descending order.

Example 2: Sorting Data by Multiple Columns

Suppose we have a table of employee data that contains the following columns:

– EmployeeName

– Department

– Salary

To sort this data first by the Department column in ascending order, and then by the Salary column in descending order, we can use the following formula:


ORDERBY(EmployeeData, Department, ASC, Salary, DESC)


This formula sorts the EmployeeData table by the Department column in ascending order, and then by the Salary column in descending order.

The ORDERBY function in Power BI is a powerful tool that can help you sort data in a specific order. By using this function, you can easily sort data by one or more columns and display it in a meaningful way. Use the examples provided in this article to understand how to use this function in your own projects.

Power BI DAX Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)