Forum Discussion

GGG123's avatar
GGG123
Regular Visitor
2 years ago
Solved

Issue with List.Max ([Date]) in power query

This formula

 

   Date.From(List.Max(Table.Column(#"Reordered Columns", [Date]))) - Date.From([Date])

 

is returning this error Expression.

 

   Error:

   We cannot convert the value #date(2024, 1, 15) to type Text.
   Details:
   Value=15/01/2024
   Type=[Type]

 

The column Date in power query is Type--> Date

 

I'm trying to get the latest date from the column Date and return for each date in the column the difference between the latest date and the date in each row.

 

How do I make this work?

  • GGG123's avatar
    GGG123
    2 years ago

    I finally worked it out. All I did is to go at the beginning of the code and Filtered Out "Undeposited Items" which was mentioned in the error I was getting 'DataFormat.Error: We couldn't parse the input provided as a Date'.

    The thing that I couldnt understand is that when looking at the Column Profile, everything showed 0 Error and the count seemed to be all in order. 

    Thanks for your help anyway!

8 Replies

  • ManuelBolz's avatar
    ManuelBolz
    Responsive Resident

    Hello GGG123  ,

    If my post helped you, please give me a 👍kudos and mark this post with Accept as Solution.

    Try this solution.

     

    let
        #"Reordered Columns" = YOURCODE
        LatestDate = List.Max(Table.Column(#"Reordered Columns", "Date")),
        AddedDateDifference = Table.AddColumn(Source, "Date Difference", each Duration.Days(LatestDate - [Date]), Int64.Type)
    in
        AddedDateDifference

     



    Best regards from Germany
    Manuel Bolz


    🟦Follow me on LinkedIn
    🟨How to Get Your Question Answered Quickly
    🟩Fabric Community Conference
    🟪My Solutions on Github

  • GGG123's avatar
    GGG123
    Regular Visitor

     

    Now I'm getting this error:

       DataFormat.Error: We couldn't parse the input provided as a Dat

    It's so weird because until last month I never had problems with this Power Query model. 

    Also, when I use the formula List.Max to find the latest date on a different paper, it works fine. 

    I tried to changed the Date as Locale and play around a bit but still the same error.

    • ManuelBolz's avatar
      ManuelBolz
      Responsive Resident

      Hello @ ,

      If my post helped you, please give me a 👍kudos and mark this post with Accept as Solution.


      Do you perhaps have a screenshot of your data table or an excerpt of the data or the M-Code? It looks like your column is not correctly defined as a Date data type. In the following screenshot I have added my solution to some test data.

       


      Best regards from Germany
      Manuel Bolz


      🟦Follow me on LinkedIn
      🟨How to Get Your Question Answered Quickly
      🟩Fabric Community Conference
      🟪My Solutions on Github

      • GGG123's avatar
        GGG123
        Regular Visitor

        Thnaks for all your answers. However, I ve tried that too and the data seems fine. 

        See below:

         

         

        I also tried to look for the 'Undeposited Items' mentioned in the Error but the column seems to be having only dates, as it should.