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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
kucluk_ok
Frequent Visitor

Change data duration to seconds from format d h m s

I Have raw data duration , where the format is not standard like this

kucluk_ok_1-1678764488049.png

i want to convert from Column "Down" to column "inSEC" using this query to manage the d=86400 seconds, h=3600seconds , m =60 seconds

inSEC = SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(Report[Down],"d","*86400"),"h","*3600"),"m","*60"),"s","*1")," ","+")

 

and i want to the query automaticly calculate the "multiply" and "add"

example in 31d = 31*86400 = 2,678,400 seconds

 

 

 

 

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

inSec = 
SUMX (
    ADDCOLUMNS (
        DATATABLE (
            "n", STRING,
            "f", INTEGER,
            {
                { "d", 86400 },
                { "h", 3600 },
                { "m", 60 },
                { "s", 1 }
            }
        ),
        "@sec",
            VAR _p =
                SUBSTITUTE (
                    SUBSTITUTE (
                        SUBSTITUTE (
                            MID ( 'Report'[Down], 1, FIND ( [n], 'Report'[Down],, 1 ) - 1 ),
                            "m",
                            "|"
                        ),
                        "h",
                        "|"
                    ),
                    "d",
                    "|"
                )
            RETURN
                VALUE ( 0 & PATHITEM ( _p, PATHLENGTH ( _p ) ) ) * [f]
    ),
    [@sec]
)

View solution in original post

4 REPLIES 4
wdx223_Daniel
Super User
Super User

inSec = 
SUMX (
    ADDCOLUMNS (
        DATATABLE (
            "n", STRING,
            "f", INTEGER,
            {
                { "d", 86400 },
                { "h", 3600 },
                { "m", 60 },
                { "s", 1 }
            }
        ),
        "@sec",
            VAR _p =
                SUBSTITUTE (
                    SUBSTITUTE (
                        SUBSTITUTE (
                            MID ( 'Report'[Down], 1, FIND ( [n], 'Report'[Down],, 1 ) - 1 ),
                            "m",
                            "|"
                        ),
                        "h",
                        "|"
                    ),
                    "d",
                    "|"
                )
            RETURN
                VALUE ( 0 & PATHITEM ( _p, PATHLENGTH ( _p ) ) ) * [f]
    ),
    [@sec]
)

I Got it, why error, because thereis space between data, i add subtitute to remove space

 

Column = 
SUMX (
    ADDCOLUMNS (
        DATATABLE (
            "n", STRING,
            "f", INTEGER,
            {
                { "d", 86400 },
                { "h", 3600 },
                { "m", 60 },
                { "s", 1 }
            }
        ),
        "@sec",
            VAR _p =
               SUBSTITUTE( SUBSTITUTE (
                    SUBSTITUTE (
                        SUBSTITUTE (
                            MID ( 'Report'[Down], 1, FIND ( [n], 'Report'[Down],, 1 ) - 1 ),
                            "m",
                            "|"
                        ),
                        "h",
                        "|"
                    ),
                    "d",
                    "|"
                )," ","")
            RETURN
                VALUE ( 0 & PATHITEM ( _p, PATHLENGTH ( _p ) ) ) * [f]
    ),
    [@sec]
)

 

I Got error- " cannot convert value 0 45 of type Text to type number"

 

add one more subtitute to remove space from data.

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.