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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors