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.
Hi,
i have 2 dates columns. i want to calculate the "duration" of start date and end date and the format should be like "5 year and 4 months". how to do it in DAX
Thanks,
Hi @HassanAli123 ,
Has your problem been solved by @jdbuchanan71 's solution? If yes, please consider accept it as the solution to help the other members find it more quickly. If not, please feel free to let me know.
Best Regards,
Community Support Team _ kalyj
Here is one I was messing with that does just years and months.
Duration =
VAR _Months = DATEDIFF ( 'Table'[Start Date], 'Table'[End Date], MONTH )
VAR _Years = INT ( DIVIDE ( _Months, 12 ) )
VAR _RemMonths = MOD ( _Months, 12 )
VAR _YearText = IF ( _Years = 0, BLANK(), IF ( _Years = 1, _Years & " year and ", _Years & " years and " ) )
VAR _MonthText = _RemMonths & IF ( _RemMonths = 1, " month", " months" )
RETURN
_YearText & _MonthText
Measure = VAR __daysinMonth = DAY(EOMONTH([Date1],0)) VAR __years = DATEDIFF([Date1],[Date2],YEAR) - 1 VAR __months = IF(MONTH([Date1])<MONTH([Date2]),MONTH([Date2])-MONTH([Date1]),12-MONTH([Date1])+MONTH([Date2])-1) VAR __days = IF(DAY([Date1])<DAY([Date2]),DAY([Date2])-DAY([Date1]),DAY([Date2])+(__daysinMonth-DAY([Date1]))) RETURN __years & " year, " & __months & " months and " & __days & " days"
//Try this with your requirements
Did I answer your question? If so, please mark my post as a solution!
Proud to be a Super User!
referring you to this link
Did I answer your question? If so, please mark my post as a solution!
Proud to be a Super User!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
115 | |
99 | |
88 | |
70 | |
62 |
User | Count |
---|---|
151 | |
120 | |
103 | |
87 | |
68 |