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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
prabhu_rathnam
New Member

DUARTION

Hi

 

Question:

Table

Job_name, starttime, endtime

ods, 5/4/2018 01:01:23, 5/4/2018 01:02:40

ods, 5/4/2018 01:15:10, 5/4/2018 01:15:40

edw, 5/4/2018 01:04:18, 5/4/2018 01:06:54

edw, 5/4/2018 01:18:21, 5/4/2018 01:20:26

 

Answer:

i want to get report as:

ods and edw starttime and endtime in a same row with duration between (edw_starttime -ods_starttime)

 

5/4/2018 01:01:23, 5/4/2018 01:02:40, 5/4/2018 01:18:21, 5/4/2018 01:20:26, Duration

 

Can someone please help me..

1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @prabhu_rathnam,

 

First, add an index column with below M code.

let
    Source = Excel.Workbook(File.Contents("C:\Users\xxxx\Desktop\Sample Data.xlsx"), null, true),
    DUARTION_Sheet = Source{[Item="DUARTION",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(DUARTION_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Job_name", type text}, {"starttime", type datetime}, {"endtime", type datetime}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Job_name"}, {{"New Col", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded New Col" = Table.ExpandTableColumn(#"Grouped Rows", "New Col", {"starttime", "endtime", "Index"}, {"New Col.starttime", "New Col.endtime", "New Col.Index"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded New Col",{{"New Col.starttime", "starttime"}, {"New Col.endtime", "endtime"}, {"New Col.Index", "Index"}})
in
    #"Renamed Columns"

1.PNG

 

Then, in data view, add a calculated column.

edw_starttime -ods_starttime =
IF (
    DUARTION[Job_name] = "edw",
    DATEDIFF (
        CALCULATE (
            MAX ( DUARTION[starttime] ),
            FILTER (
                DUARTION,
                DUARTION[Index] = EARLIER ( DUARTION[Index] )
                    && DUARTION[Job_name] <> EARLIER ( DUARTION[Job_name] )
            )
        ),
        DUARTION[starttime],
        SECOND
    )
)

2.PNG

 

New a calculated table.

DUARTION2 =
UNION (
    SELECTCOLUMNS (
        DUARTION,
        "Job_name", DUARTION[Job_name],
        "Index", DUARTION[Index],
        "starttime", DUARTION[starttime],
        "endtime", DUARTION[endtime]
    ),
    SELECTCOLUMNS (
        DUARTION,
        "Job_name", "duration",
        "Index", DUARTION[Index],
        "startname", BLANK (),
        "endtime", DUARTION[edw_starttime -ods_starttime]
    )
)

3.PNG

 

Insert a matrix to display data from 'DUARTION2'.

4.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @prabhu_rathnam,

 

First, add an index column with below M code.

let
    Source = Excel.Workbook(File.Contents("C:\Users\xxxx\Desktop\Sample Data.xlsx"), null, true),
    DUARTION_Sheet = Source{[Item="DUARTION",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(DUARTION_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Job_name", type text}, {"starttime", type datetime}, {"endtime", type datetime}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Job_name"}, {{"New Col", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded New Col" = Table.ExpandTableColumn(#"Grouped Rows", "New Col", {"starttime", "endtime", "Index"}, {"New Col.starttime", "New Col.endtime", "New Col.Index"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded New Col",{{"New Col.starttime", "starttime"}, {"New Col.endtime", "endtime"}, {"New Col.Index", "Index"}})
in
    #"Renamed Columns"

1.PNG

 

Then, in data view, add a calculated column.

edw_starttime -ods_starttime =
IF (
    DUARTION[Job_name] = "edw",
    DATEDIFF (
        CALCULATE (
            MAX ( DUARTION[starttime] ),
            FILTER (
                DUARTION,
                DUARTION[Index] = EARLIER ( DUARTION[Index] )
                    && DUARTION[Job_name] <> EARLIER ( DUARTION[Job_name] )
            )
        ),
        DUARTION[starttime],
        SECOND
    )
)

2.PNG

 

New a calculated table.

DUARTION2 =
UNION (
    SELECTCOLUMNS (
        DUARTION,
        "Job_name", DUARTION[Job_name],
        "Index", DUARTION[Index],
        "starttime", DUARTION[starttime],
        "endtime", DUARTION[endtime]
    ),
    SELECTCOLUMNS (
        DUARTION,
        "Job_name", "duration",
        "Index", DUARTION[Index],
        "startname", BLANK (),
        "endtime", DUARTION[edw_starttime -ods_starttime]
    )
)

3.PNG

 

Insert a matrix to display data from 'DUARTION2'.

4.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.