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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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