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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! 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
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.

Top Kudoed Authors