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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors