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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
bogdan_elastic
New Member

Sorting by non-grouped column

Hi there,

I'm looking for some guidance or hint on the below case I'm trying to solve.

I'm working on an ODBC-based connector for a SQL datasource that lacks currently the capacity to sort/order by non-groupped columns.

In case DirectQuery is enabled, PowerBI will generate statements of the (simplified) type:

select a from (select a, b, c, d from table group by a, b) order by c, d

(below the actual null-handling sorting query). To this the datasource complains that it "[c]annot order by non-grouped columns".

There seems to be no capability in the ODBC spec to indicate support (or lack of) for this type of query. The AstVisitor functionality seems unfit for this case.

I was wonding if there's any way to indicate this incapacity to PowerBI?

 

Thanks in advance for any hint!

--b

Actual statement submitted for preparation:

select "date0"
from
(
   select "date0",
       "C1",
       case
           when "C1" is not null
           then "C1"
           else ?
       end as "C2",
       case
           when "C1" is null
           then ?
           else ?
       end as "C3"
   from
   (
       select "date0",
           "date0" as "C1"
       from "calcs"
   ) as "ITBL"
   group by "date0",
       "C1"
) as "ITBL"
order by "ITBL"."C2",
       "ITBL"."C3"

 

2 REPLIES 2
Mariusz
Community Champion
Community Champion

Hi @bogdan_elastic 

 

Would you be able to visualize your problem, as a sample of data in the current state and what is the outcome that you expect?

Please, can you clarify, what do you mean by "I was wonding if there's any way to indicate this incapacity to PowerBI?"

 
Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski

 

 

Hi @Mariusz ,

 


Would you be able to visualize your problem, as a sample of data in the current state and what is the outcome that you expect?

Please, can you clarify, what do you mean by "I was wonding if there's any way to indicate this incapacity to PowerBI?"

I am looking for a way to flag to PowerBI that the data source can't order by a column, if that column is not used for grouping.

Ideally, there would be a setting in SqlCapabilities passed to Odbc.DataSource, as an example.

 

So, in the full example I've given, ideally PowerBI would also group by "C2" and "C3" if ordering by these columns.

 

Regards,

Bogdan.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.