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
Rebender
Frequent Visitor

How to sort a Time Duration

I have created a calculated column that gives me a Time Duration in Days, Hours, Minutes, Seconds.  What I would like to do now is be able to sort the column in my table visual, but it is not putting it in the correct order.  Please see the attached image.  Can someone tell me how to be able to sort by this column?  Thank you for your assistance!

Duration Sort Image.png

1 ACCEPTED SOLUTION

I solved my problem by fixing the formatting of the Value.  I added a second "0" to the day portion of the following code and it worked.

FORMAT(dayNo,"#00")&" day "&FORMAT(hourNo,"#00")&":"&FORMAT(minuteNO,"#00")&":"&FORMAT(secondNo,"#00")

View solution in original post

3 REPLIES 3
v-yulgu-msft
Employee
Employee

Hi @Rebender,

 

Please create calculated columns.

Final rank =
RANKX (
    Dataset2,
    (
        RANKX ( Dataset2, LEFT ( Dataset2[Duration], 2 ),, ASC )
            + DIVIDE (
                RANKX ( Dataset2, RIGHT ( Dataset2[Duration], 8 ),, ASC ),
                COUNTROWS ( Dataset2 ) + 1
            )
    ),
    ,
    ASC,
    DENSE
)

1.PNG2.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you for your quick response, but that did not work.  It still sorted it in the same order.  If you notice in the picture, it is going from 1 day, 11 day, 12, 2 day.  I need it to go 1 day, 2 day, 11 day, 12 day.  Would it be better if I used the mintes column that I used to format my duration in the Final Rank column instead???

I solved my problem by fixing the formatting of the Value.  I added a second "0" to the day portion of the following code and it worked.

FORMAT(dayNo,"#00")&" day "&FORMAT(hourNo,"#00")&":"&FORMAT(minuteNO,"#00")&":"&FORMAT(secondNo,"#00")

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.