Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Linnil
Helper II
Helper II

Let Statement (Step) with IF Statement

Hi everyone - I'm just learning how to make Let Statements as Steps.

I have this problem - I'm calculating Years of Service, at 30 Apr 23.

However, if the person has left / if Status is T, then the endDate = Term Date.

Is it possible to modify the statement below so it does a check for the endDate ?

 

This is my Let Statement (as a Step) so far:

let
startDate = [Hire Date],
endDate = #date(2023,04,30),
durationInDays = Duration.Days(endDate - startDate),
durationInYears = durationInDays / 365
in
durationInYears

 

I thought briefly about doing it as a conditional column, I think that's another complication.

 

Thanks for any suggestions 🙂

1 ACCEPTED SOLUTION
m_dekorte
Super User
Super User

Hi @Linnil 

 

Assuming you have a [Status] and [Term Date] field, like [Hire Date] in in your table, try this:

 

let
    startDate = [Hire Date],
    endDate = if [Status] = "T" then [Term Date] else #date(2023,04,30),
    durationInDays = Duration.Days(endDate - startDate),
    durationInYears = durationInDays / 365
in
    durationInYears

 

 

I hope this is helpful

View solution in original post

2 REPLIES 2
m_dekorte
Super User
Super User

Hi @Linnil 

 

Assuming you have a [Status] and [Term Date] field, like [Hire Date] in in your table, try this:

 

let
    startDate = [Hire Date],
    endDate = if [Status] = "T" then [Term Date] else #date(2023,04,30),
    durationInDays = Duration.Days(endDate - startDate),
    durationInYears = durationInDays / 365
in
    durationInYears

 

 

I hope this is helpful

Thank you for this! (sorry for late reply, it was a crazy week).
Have a lovely weekend 🙂

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.