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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
sandraemma
Frequent Visitor

Sort columns based on string value

Hello,

 

I am stuck on something for many days that I think should be fairly easy and any ideas can help!

I have many different statuses (over 15 different, I only show few here) and I need to sort so that the correct status is the one row that is left. If the status is completed, the whole id and all rows shold be filtered away. 

Any idea on how I can sort the ids compared to the statuses? 

If statement or case? I am fairly new to dax and power bi so I am having a hard time finding the correct way of thinking. 

 

This is the example data

Idstatus
1

started

1processing
1ready
1completed
2started
2processing
3started
3processing
3ready

 

And this is the result I want:

idstatus
2processing
3ready
1 REPLY 1
ronrsnfld
Community Champion
Community Champion

  • Group by ID
  • Custom aggregation (need to use Advanced Filter) to return only the last item in the status column associated with that ID
  • Remove any rows that have a completed status
let
    Source = Table.FromColumns({
        {1,1,1,1,2,2,3,3,3},
        {"started","Processing","ready","completed","started","Processing","started","Processing","ready"}
        },
        type table[id=Int64.Type, status=text]
    ),

//Group by ID and return the "Last" item in the status column
    #"Grouped Rows" = Table.Group(Source, {"id"}, {
        {"status", each List.Last([status]), type text}}),

//Remove any rows where last status is "completed"
    #"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each ([status] <> "completed"))
in
    #"Filtered Rows"

 

ronrsnfld_0-1675684315527.png

 

 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors