Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
9 months ago
Solved

Error when sorting rows

I encountered an error when sorting rows. I sorted two columns with Text and Whole Number types in ascending order. The column that caused the error was the one with the Date data type. I made sure t...
  • Royel's avatar
    9 months ago

    Hi Anonymous I have loaded same formated data and solve this in a optimal way 

    here it is before the fix: 

     

    After Fixing: 

     

    Complete M-Code: 

    let
        Source = Table.FromRows(
            {
                {"1",  "Mon 7/21/25", "Wed 7/23/25"},
                {"2",  "Thu 7/24/25", "Mon 7/28/25"}
            },
            {"TaskID",  "Start_Date", "Finish_Date"}
        ),
    
        CleanAndConvert = Table.TransformColumns(
            Source,
            {
                {"TaskID", each Number.FromText(_), Int64.Type},
                {"Start_Date", each Date.FromText(Text.AfterDelimiter(_, " "), [Culture="en-US"]), type date},
                {"Finish_Date", each Date.FromText(Text.AfterDelimiter(_, " "), [Culture="en-US"]), type date}
            }
        ),
    
        Sorted = Table.Sort(CleanAndConvert, {{"Start_Date", Order.Ascending}})
    in
        Sorted

     

    Find this helpful? ✔ Give a Kudo • Mark as Solution – help others too!

    I’d love to stay connected. Join me on LinkedIn for more tips, learning paths, and real-world Fabric & Power BI solutions.