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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Kogika
New Member

Textual Display of Days (DATEDIFF)

Hi,

 

I`m using the DATEDIFF function and I`m getting the expected results in number of days.

 

What I`m not being able to do is to display the days in a more textual form. For example, If I have the number 398 days, I want to display " 1 year, 1 month and 3 days".

 

Ideally, I would like to use plurals/singular on Years Months and Days everytime it is applicable.

 

I've been struggling with that bu couldn't find any particular approach to make it work.

 

Tks!

 

 

1 ACCEPTED SOLUTION
nandukrishnavs
Super User
Super User

@Kogika 

 

Try this example

 

 

DateText = 
var _fulldays= 35
//replace 35 with your measure 
var _year= QUOTIENT(_fulldays,365)
var _month= QUOTIENT(MOD(_fulldays,365),30)
var _day= MOD(MOD(_fulldays,365),30)
var _yearText = IF(_year=1,"1 year",IF(_year>1,_year&" years",BLANK()))
var _monthText= IF(_month=1,"1 month",IF(_month>1,_month&" months",BLANK()))
var _dayText= IF(_day=1,"1 day",IF(_day>1,_day&" days",BLANK()))
var _finalText= _yearText&" "&_monthText&" "&_dayText
return _finalText

 

You may have to tweak the code a little bit.

Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂


Regards,
Nandu Krishna

View solution in original post

2 REPLIES 2
nandukrishnavs
Super User
Super User

@Kogika 

 

Try this example

 

 

DateText = 
var _fulldays= 35
//replace 35 with your measure 
var _year= QUOTIENT(_fulldays,365)
var _month= QUOTIENT(MOD(_fulldays,365),30)
var _day= MOD(MOD(_fulldays,365),30)
var _yearText = IF(_year=1,"1 year",IF(_year>1,_year&" years",BLANK()))
var _monthText= IF(_month=1,"1 month",IF(_month>1,_month&" months",BLANK()))
var _dayText= IF(_day=1,"1 day",IF(_day>1,_day&" days",BLANK()))
var _finalText= _yearText&" "&_monthText&" "&_dayText
return _finalText

 

You may have to tweak the code a little bit.

Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂


Regards,
Nandu Krishna

Thanks @nandukrishnavs , it worked perfectly! Very nice approach.

 

Regards

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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