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

Power Query

Hi,

 

My original table looks like this:

 

Afiq_Danial_4-1669311112672.png

 

 

I then created some steps which finds the start job date and end job date based Job Name column. However, it also includes the "Cancelled" Booking Types. I want to exclude rows with the "Cancelled" booking type.

 

The table that I have right now looks like this after the steps:

Afiq_Danial_3-1669311084712.png

 

 

 

The correct job duration for Job A should be 1/10/2022 to 28/10/2022.

The correct job duration for Job B should be 2/11/2022 to 21/11/2022

 

Does anyone know what I am missing in my steps? I'm quite unfamiliar with the Power Query so I would appreciate all the help i can get. I'll upload the file here. Thanks Alot.

 

https://drive.google.com/drive/folders/1PFxkYhXnHubuT3N1hQ2vJiNikYV4DibC?usp=share_link

1 ACCEPTED SOLUTION
v-yadongf-msft
Community Support
Community Support

Hi @Anonymous ,

 

If you want to transform date in Power Query, please crete two columns:

Start  job duration = List.Max(Table.SelectRows(#"Promoted Headers",(x)=>x[Job Name]=[Job Name] and x[Booking Type]<>"Cancelled")[Start Date])

vyadongfmsft_0-1669368658078.png

 

End job duration = List.Max(Table.SelectRows(#"Promoted Headers",(x)=>x[Job Name]=[Job Name] and x[Booking Type]<>"Cancelled")[End Date])

vyadongfmsft_1-1669368730243.png

 

Result you want:

vyadongfmsft_2-1669368841856.png

 

M code for your reference:

let
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Staff Name", type text}, {"Job Name", type text}, {"Start Date", type date}, {"End Date", type date}, {"Booking Type", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Start  job duration", each List.Max(Table.SelectRows(#"Promoted Headers",(x)=>x[Job Name]=[Job Name] and x[Booking Type]<>"Cancelled")[Start Date])),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "End job duration", each List.Max(Table.SelectRows(#"Promoted Headers",(x)=>x[Job Name]=[Job Name] and x[Booking Type]<>"Cancelled")[End Date]))
in
    #"Added Custom1"

 

 

Best regards,

Yadong Fang

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

2 REPLIES 2
v-yadongf-msft
Community Support
Community Support

Hi @Anonymous ,

 

If you want to transform date in Power Query, please crete two columns:

Start  job duration = List.Max(Table.SelectRows(#"Promoted Headers",(x)=>x[Job Name]=[Job Name] and x[Booking Type]<>"Cancelled")[Start Date])

vyadongfmsft_0-1669368658078.png

 

End job duration = List.Max(Table.SelectRows(#"Promoted Headers",(x)=>x[Job Name]=[Job Name] and x[Booking Type]<>"Cancelled")[End Date])

vyadongfmsft_1-1669368730243.png

 

Result you want:

vyadongfmsft_2-1669368841856.png

 

M code for your reference:

let
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Staff Name", type text}, {"Job Name", type text}, {"Start Date", type date}, {"End Date", type date}, {"Booking Type", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Start  job duration", each List.Max(Table.SelectRows(#"Promoted Headers",(x)=>x[Job Name]=[Job Name] and x[Booking Type]<>"Cancelled")[Start Date])),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "End job duration", each List.Max(Table.SelectRows(#"Promoted Headers",(x)=>x[Job Name]=[Job Name] and x[Booking Type]<>"Cancelled")[End Date]))
in
    #"Added Custom1"

 

 

Best regards,

Yadong Fang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

v-yadongf-msft
Community Support
Community Support

Hi @Anonymous ,

 

I think you can transform date in Power BI.

 

Please create two columns:

Start job duration =
MINX (
    FILTER (
        'Table',
        'Table'[Booking Type] <> "Cancelled"
            && 'Table'[Job Name] = EARLIER ( 'Table'[Job Name] )
    ),
    [Start Date]
)


End job duration =
MAXX (
    FILTER (
        'Table',
        'Table'[Booking Type] <> "Cancelled"
            && 'Table'[Job Name] = EARLIER ( 'Table'[Job Name] )
    ),
    [End Date]
)

 

The result you want:

vyadongfmsft_0-1669345856432.png

 

Best regards,

Yadong Fang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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 Fabric 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.