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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Complex data transform

I have large amounts of raw fault data.

codetimestatus
x1232019-04-22T23:57:00ok
x1232019-04-23T01:00:00faulty
x1232019-04-23T02:00:00ok
x1232019-04-23T23:00:00faulty
x1232019-04-24T01:00:00ok

I need to transform this to show how long an item has been in a faulty state on a given day. So on the 23rd, the item was in a faulty state between 1 and 2a.m and then again between 11pm until past midnight.

codeday% of day faulty
x12323/04/20198.30%

 (8.30% = 2/24 hours)

Can I do this easily in Power BI or should I use another tool such as Azure Data Factory?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Many thanks for your reply @Zubair_Muhammad . I found another solution first that somebody posted on stackoverflow:

 

https://stackoverflow.com/questions/55825688/tool-recommendation-for-data-transform

 

View solution in original post

3 REPLIES 3
Zubair_Muhammad
Community Champion
Community Champion

Hi @Anonymous 

 

try this mEASURE.

It works with sample data. I added few more rows to test

 

Measure =
SUMX (
    ADDCOLUMNS (
        Table1,
        "TimeDifference",
        VAR NextOk =
            MAXX (
                TOPN (
                    1,
                    FILTER ( Table1, [status] = "ok" && [time] > EARLIER ( [time] ) ),
                    [time], ASC
                ),
                [time]
            )
        VAR FirstStatusisOK =
            MINX ( TOPN ( 1, Table1, [time], ASC ), [status] ) = "ok"
        VAR FirstStatusOKtime =
            MINX ( TOPN ( 1, Table1, [time], ASC ), [time] )
        RETURN
            IF (
                ISBLANK ( NextOk ),
                24 - HOUR ( [Time] ),
                DATEDIFF ( [time], NextOk, HOUR )
            )
                + IF ( FirstStatusisOK, HOUR ( FirstStatusOKtime ) )
    ),
    IF ( [status] = "faulty", [TimeDifference] )
) / 24

@Anonymous 

 

See the attached file as well

 

kjlj.png

Anonymous
Not applicable

Many thanks for your reply @Zubair_Muhammad . I found another solution first that somebody posted on stackoverflow:

 

https://stackoverflow.com/questions/55825688/tool-recommendation-for-data-transform

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors