How to calculate duration of years in power query

Anitha 0 Reputation points
2023-02-02T20:34:52.83+00:00

I have to calculate duration between current year and the year of hire of employees.

I have column set up for year of hire

Currently I used formula in custom column

2023-[year of hire]

how can I write a formula where I don’t have to update current year?

please help

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,760 questions
Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,982 questions
Office Management
Office Management
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Management: The act or process of organizing, handling, directing or controlling something.
2,190 questions
PowerPoint Management
PowerPoint Management
PowerPoint: A family of Microsoft presentation graphics products that offer tools for creating presentations and adding graphic effects like multimedia objects and special effects with text.Management: The act or process of organizing, handling, directing or controlling something.
232 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,731 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 44,411 Reputation points
    2023-02-03T17:14:30.97+00:00
    
    Hi. Thank you for your question and reaching out. I’d be more than happy to help you with your query.
    
    You can calculate the duration of years in Power Query by subtracting the start date from the end date and then dividing the result by the number of days in a year. Here's an example in Power Query M language:
    
    
    let
        startDate = #date(2019,1,1),
        endDate = #date(2023,12,31),
        durationInDays = Duration.Days(endDate - startDate),
        durationInYears = durationInDays / 365
    in
        durationInYears
    
    
    
    This will give you the duration in decimal years. If you want the duration in whole years, you can round the result down using the RoundDown function. For example:
    
    
    let
        startDate = #date(2019,1,1),
        endDate = #date(2023,12,31),
        durationInDays = Duration.Days(endDate - startDate),
        durationInYears = durationInDays / 365,
        durationInWholeYears = RoundDown(durationInYears)
    in
        durationInWholeYears
    
    
    
    This will return the number of full years between the start and end dates.
    
    
    
    If the reply was helpful, please don’t forget to upvote or accept as answer, thank you.
    
    3 people found this answer helpful.

  2. Emily Hua-MSFT 27,651 Reputation points
    2023-02-03T06:35:21.9266667+00:00

    Hi @Anitha

    I suggest you post this issue to Power BI forum:

    https://community.powerbi.com/t5/Power-Query/bd-p/power-bi-services

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.


    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.


    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.