Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Pol
Frequent Visitor

Power BI Report Builder Distinct and Order By

Hi,

 

I would like to ask regarding to this query error that I'm encountered in power BI report builder I'm using an ODBC connection to my excel data

Pol_0-1746674092445.pngPol_1-1746674134264.png

 

1 ACCEPTED SOLUTION
v-kpoloju-msft
Community Support
Community Support

Hi @Pol,

Thank you for reaching out to the Microsoft fabric community forum. Thank you @BhavinVyas3003, for your inputs on this issue.

I understand you are experiencing a syntax error in Power BI Report Builder when using SELECT DISTINCT with an ORDER BY clause via an ODBC connection to Excel.

This issue arises due to a limitation in the Microsoft ODBC Excel driver, which does not permit ORDER BY on columns not included in the SELECT DISTINCT clause.
 

Use only DISTINCT in SQL and apply sorting inside Report Builder:

SELECT DISTINCT OrderDate FROM [Sheet1$]


Then go to Dataset Properties > Sorting and add Order Date as a sort of expression. This moves the sort of logic to the report layer, bypassing SQL syntax restrictions.

Use GROUP BY with ORDER BY:

SELECT OrderDate FROM [Sheet1$]

GROUP BY OrderDate

ORDER BY OrderDate

 

This gives a unique list of dates and allows SQL-level sorting without conflict.  Pre-process the data using Power Query in Excel or Power BI Desktop before connecting it to Report Builder. This allows for complete control over sorting, transformations, and column structure beforehand.

If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

Thank you for using Microsoft Community Forum.

View solution in original post

3 REPLIES 3
v-kpoloju-msft
Community Support
Community Support

Hi @Pol,

Thank you for reaching out to the Microsoft fabric community forum. Thank you @BhavinVyas3003, for your inputs on this issue.

I understand you are experiencing a syntax error in Power BI Report Builder when using SELECT DISTINCT with an ORDER BY clause via an ODBC connection to Excel.

This issue arises due to a limitation in the Microsoft ODBC Excel driver, which does not permit ORDER BY on columns not included in the SELECT DISTINCT clause.
 

Use only DISTINCT in SQL and apply sorting inside Report Builder:

SELECT DISTINCT OrderDate FROM [Sheet1$]


Then go to Dataset Properties > Sorting and add Order Date as a sort of expression. This moves the sort of logic to the report layer, bypassing SQL syntax restrictions.

Use GROUP BY with ORDER BY:

SELECT OrderDate FROM [Sheet1$]

GROUP BY OrderDate

ORDER BY OrderDate

 

This gives a unique list of dates and allows SQL-level sorting without conflict.  Pre-process the data using Power Query in Excel or Power BI Desktop before connecting it to Report Builder. This allows for complete control over sorting, transformations, and column structure beforehand.

If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

Thank you for using Microsoft Community Forum.

Hi @Pol,

 

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

BhavinVyas3003
Solution Sage
Solution Sage

Check these options,

  • Use only DISTINCT, then sort inside Report Builder:

SELECT DISTINCT OrderDate FROM [Sheet1$]

→ Set sorting in Report → Dataset → Properties → Sort by OrderDate.

 

  • Use GROUP BY with ORDER BY

SELECT OrderDate FROM [Sheet1$] GROUP BY OrderDate ORDER BY OrderDate

 

  • If possible, pre-process the Excel data in Power BI Desktop or Excel using Power Query, then publish or connect to that transformed file.

Thanks,
Bhavin
Problem solved? Hit “Accept as Solution” and high-five me with a Kudos! Others will thank you later!

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

May 2025 Monthly Update

Fabric Community Update - May 2025

Find out what's new and trending in the Fabric community.