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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
InterSimi
Helper II
Helper II

Calculate age of item based on dates after 1/1/2018

Hi,

 

I wish to add a calculated column in my PowerBI report, which calculates the hours saved based on the date provided and hourly savings up until todays date. The only caveat is that I only need the hours to be calculated for 2018.

 

We have a Sharepoint list, which has columns for "start date" and monthly savings (in hours). However we have projects which go back a few years, which I do not wish to include.

 

The DAX I have for the project run time is:

 

Project Run Time = 
IF('LEANSavings '[OccurenceValue] = "Re-Occurring Savings", 
    (TODAY() - 'LEANSavings '[SavingsStartDate].[Date])/30, 
    1)

I wish to add something to state that if

LEANSavings '[SavingsStartDate].[Date]  

 is before 1/1/2018, then the date should be 1/1/2018

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Project Run Time = 
VAR startdate = IF('LEANSavings '[SavingsStartDate].[Date] < DATE(2018,1,1),DATE(2018,1,1),'LEANSavings '[SavingsStartDate].[Date])
RETURN
IF('LEANSavings '[OccurenceValue] = "Re-Occurring Savings", 
    (TODAY() - startdate)/30, 
    1)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

Project Run Time = 
VAR startdate = IF('LEANSavings '[SavingsStartDate].[Date] < DATE(2018,1,1),DATE(2018,1,1),'LEANSavings '[SavingsStartDate].[Date])
RETURN
IF('LEANSavings '[OccurenceValue] = "Re-Occurring Savings", 
    (TODAY() - startdate)/30, 
    1)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

That is fantastic Greg, thank you.

 

I did start to do something very similar, buit keep forgetting whether to use 'Let' or Var'. Occassionally when I type in Var, PoiwerBI only gives me options like Var.P

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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