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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Frequent Visitor

Sort order in power query and data view. DAX for grouping ids.

Will adding an index in power query and ordering it by index in ascending order there ensure that the same order will be maintained in the data view as well in Power BI? 

I have the data table below and would like to group the data by each object_id first and then for each of these ids I would like to group the data as per the state from the end of the '0' to next '0' in descending order of state_time. For example in the table below 6:18 to 6:19 should be grouped into a single id. I had put an index in the power query initially after sorting object_id and state_time in descending order. Then added a calculated column in the data view. The DAX is given below. Just wanted to check if the sort order from Power Query to Data view will be maintained. The DAX below actually works but I just wanted to make sure it i accurate and will work always since it is dependend on teh index number. Thansk in advance :). 




Solution Supplier
Solution Supplier

Hi @Vivek2456,


I have a question. Will you be using the grouped table in the creation of measures and is this the table that you are looking for?




If yes, then for the sake of performance, I would suggest you to do the same data transformation in Power Query using the Group By functions and taking the Max of state_time column as per your requirement.


I have not used the index column, and instead added a date column, and did a Group By based on that.


I am attaching my PBIX for your reference and please provide some more information if the solution is not what you are looking for.


To answer you other question, the data view will not necessarily maintain the sort order but you can always sort by any column, which is why when it comes to transformation, Power Query is better than DAX.


Hope this helps and apologies if I have not understood the problem correctly.


Thank you,

Vishesh Jain

Did I answer your question?
If yes, then please mark my post as a solution!

Thank you,
Vishesh Jain

Proud to be a Super User!

Thanks. I actually found a solution. But now the scope had changed. Please see below. Apologies for late response.

Helpful resources

Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City


Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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