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
bourne2000
Helper V
Helper V

Calculating 1 YEAR, 2 YEARS from today?

Hi

 

I am having lease date  in my table

 

bourne2000_1-1641251121040.png

 

I need to create a calculated column with the following,

 

Needs to create a category for one year from today, two years from today, three years from today, four years from today and 5+ years from today

 

Calculated column output as follow

 

1 year

2 years

3 years

4 years

5+ years

 

Can anyone please advise how to do that? I tried with DateADD function but not successful

 

here is the sample pbix file https://we.tl/t-SULP415YmN

1 ACCEPTED SOLUTION

@bourne2000 can you confirm with a screenshot of the formula bar?

My code appears to be working fine in your example file.

ebeery_0-1641254479771.png

 

View solution in original post

7 REPLIES 7
ebeery
Solution Sage
Solution Sage

@bourne2000 something like below should work, if I understand your requirement correctly:

Lease Category = 
VAR _Age = DATEDIFF(TODAY(), 'iolp-leases'[Lease date],YEAR)
VAR _Result = 
SWITCH(
    TRUE(),
    _Age >= 5, "5+ years",
    _Age >= 4, "4 years",
    _Age >= 3, "3 years",
    _Age >= 2, "2 years",
    _Age >= 1, "1 year",
    "Less than 1 year"
) 
Return
_Result

 

ebeery_0-1641252987177.png

 



@ebeery -Thanks for your reply

 

I checked the calculation is not correct. It shows everything less than one year

 

bourne2000_0-1641254231060.png

 

@bourne2000 can you confirm with a screenshot of the formula bar?

My code appears to be working fine in your example file.

ebeery_0-1641254479771.png

 

That's the same column. I just changed the column name. 

@bourne2000 I'm not sure where you're going wrong either, but linked below is my version of your file with the column added and working correctly. 

https://drive.google.com/file/d/1k0yDUyHK7Z8QMZATZYR6lvFKtGw2f9zu/view?usp=sharing 

@ebeery 

not sure why I am not getting it

bourne2000_0-1641256953328.png

 

@bourne2000 In your first screenshot you showed "Lease Expiration Date", but your screenshot above shows "Lease Effective Date" being used.

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.