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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Vivek2456
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 :). 

Vivek2456_0-1668407701678.png

Vivek2456_1-1668408422886.png

 

2 REPLIES 2
visheshjain
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?

 

visheshjain_0-1668410568065.png

 

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. 

https://community.powerbi.com/t5/Desktop/Multiple-overlapping-dates-and-grouping-data-based-on-a-flo...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.