How do I use a function on a table column in Query, when I want the inputted report to translate into a different number in Excel? Update: I need syntax help

Marissa Austin 0 Reputation points
2024-08-20T21:05:09.7233333+00:00

I know my title is confusing, it's the best I could do.

I am inputting an Excel report into Query, to organize it and lay it out on a spreadsheet. One of my values I want to show up as a duration, based on the date that came in on the report.

For example, if the report I upload to Query has the invoice dates, 8/18/24, 8/19/24, and 8/20/24, I want my spreadsheet to reflect that the invoices are 3, 2, and 1 days old.

I just can not figure out how to get Query to make the calculations, and I'm very out of practice in coding. Any ideas?

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
5,159 questions
Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,977 questions
Excel Management
Excel Management
Excel: A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.Management: The act or process of organizing, handling, directing or controlling something.
1,729 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,610 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Jiajing Hua-MFST 10,885 Reputation points Microsoft Vendor
    2024-08-21T06:38:02.0433333+00:00

    Hi @Marissa Austin

    I suggest you try DATEDIFF function, like Days Duration = DATEDIFF([Invoice Date], TODAY(), DAY)


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



  2. riny 170 Reputation points
    2024-08-22T08:10:38.3633333+00:00

    The use of DateTime.LocalNow requires a pair of opening and closing parenthesis (), similar to TODAY() in Excel. That the first error in the formula.

    Then, Duration.TotalDays expects a number (not two date argements) from subtracting two dates, for example end_date - start_date. Both have to be of the Date data type. You can not subtract a Date from a DateTime.

    Use this code in stead:

    #"Invoice Date" = Int64.From(DateTime.LocalNow()) - Number.From([Invoice Date])


  3. riny 170 Reputation points
    2024-09-08T07:22:22.9+00:00

    You forgot the pair of parenthesis after the function name.

    User's image

    Use DateTime.LocalNow() in stead.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.