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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
ssk_1984
Helper I
Helper I

Convert date in text format into Days

Hi All, 

 

help me create measure to convert the below format into days.

FormatMeasure required  to convert days
11Y 5M 2D4032
5Y 2M 11D1896
11M 10D340
10D10
1M 5D35
2D2

 

ssk_1984_0-1694768001539.png

 

 

1 ACCEPTED SOLUTION
Ritaf1983
Super User
Super User

Hi @ssk_1984 
Try to add a calculated column with the DAX :

TotalDaysMonthsYears =
VAR FormatText = [Format]
VAR SpaceCount = LEN(FormatText) - LEN(SUBSTITUTE(FormatText, " ", ""))
VAR DaysPart =
    IF(
        CONTAINSSTRING(FormatText, "D"),
        IF(
            SpaceCount = 0,
            VALUE(LEFT(FormatText, FIND("D", FormatText) - 1)),
            IF(
                SpaceCount = 1,
                VALUE(MID(FormatText, FIND(" ", FormatText) + 1, FIND("D", FormatText) - FIND(" ", FormatText) - 1)),
                IF(
                    SpaceCount = 2,
                    VALUE(MID(FormatText, FIND(" ", FormatText, FIND(" ", FormatText) + 1) + 1, FIND("D", FormatText) - FIND(" ", FormatText, FIND(" ", FormatText) + 1) - 1)),
                    0
                )
            )
        ),
        0
    )
VAR MonthsPart =
    IF(
        CONTAINSSTRING(FormatText, "M"),
        IF(
            SpaceCount = 1,
            VALUE(LEFT(FormatText, FIND("M", FormatText) - 1)),
            IF(
                SpaceCount = 2,
                VALUE(MID(FormatText, FIND(" ", FormatText) + 1, FIND("M", FormatText) - FIND(" ", FormatText) - 1)),
                0
            )
        ),
        0
    )
VAR YearsPart =
    IF(
        CONTAINSSTRING(FormatText, "Y"),
        IF(
            SpaceCount = 2,
            VALUE(LEFT(FormatText, FIND("Y", FormatText) - 1)),
            0
        ),
        0
    )
RETURN DaysPart + MonthsPart * 30 + YearsPart * 365
please note: the result of the first row is 4167 (11*365+5*30+2) 
 
If you need the sample file, can download it from the Link 
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

3 REPLIES 3
ssk_1984
Helper I
Helper I

you are awsome... Thank you very much for help and invested some to bring this possible...😍

Glad to help 🙂

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile
Ritaf1983
Super User
Super User

Hi @ssk_1984 
Try to add a calculated column with the DAX :

TotalDaysMonthsYears =
VAR FormatText = [Format]
VAR SpaceCount = LEN(FormatText) - LEN(SUBSTITUTE(FormatText, " ", ""))
VAR DaysPart =
    IF(
        CONTAINSSTRING(FormatText, "D"),
        IF(
            SpaceCount = 0,
            VALUE(LEFT(FormatText, FIND("D", FormatText) - 1)),
            IF(
                SpaceCount = 1,
                VALUE(MID(FormatText, FIND(" ", FormatText) + 1, FIND("D", FormatText) - FIND(" ", FormatText) - 1)),
                IF(
                    SpaceCount = 2,
                    VALUE(MID(FormatText, FIND(" ", FormatText, FIND(" ", FormatText) + 1) + 1, FIND("D", FormatText) - FIND(" ", FormatText, FIND(" ", FormatText) + 1) - 1)),
                    0
                )
            )
        ),
        0
    )
VAR MonthsPart =
    IF(
        CONTAINSSTRING(FormatText, "M"),
        IF(
            SpaceCount = 1,
            VALUE(LEFT(FormatText, FIND("M", FormatText) - 1)),
            IF(
                SpaceCount = 2,
                VALUE(MID(FormatText, FIND(" ", FormatText) + 1, FIND("M", FormatText) - FIND(" ", FormatText) - 1)),
                0
            )
        ),
        0
    )
VAR YearsPart =
    IF(
        CONTAINSSTRING(FormatText, "Y"),
        IF(
            SpaceCount = 2,
            VALUE(LEFT(FormatText, FIND("Y", FormatText) - 1)),
            0
        ),
        0
    )
RETURN DaysPart + MonthsPart * 30 + YearsPart * 365
please note: the result of the first row is 4167 (11*365+5*30+2) 
 
If you need the sample file, can download it from the Link 
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors