Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi I have a data that looks currently like this:
The start date and end date in the table above are for each staff. For example, Chloe is assigned to Job A from 2 October 2022 to 21 October 2022. However, Job A has been running from 1 October 2022 to 31 October.
My goal right now is to take the minimum and maximum date of each job and put it in a new column. I want my data table to look like this now:
Note: I have to do this in Power Query Editor, I'm not that familiar with Power Query so I would appreciate all the help i can get.
Thank You!
Solved! Go to Solution.
Hi @Afiq_Danial ,
You may try this sample:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsxLqVTSUfLKT1JwBNKGBvrG+kYGRkZQtiGEE6sTreRUVJmYh6rUEEmpoQlCqXNGTn4qqlIjJKVGSKYGJxYlZkCVOoGkDfXN4UoN9Y0NEEq9EnNTi1GVGhgjqUV2gWNxRk5qJZpiSyTFcDfEAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Staff Name" = _t, #"Job Name" = _t, #"Start Date" = _t, #"End Date" = _t]),
DefaultDataTypes = Table.TransformColumnTypes(Source,{{"Start Date", type date}, {"End Date", type date}}),
// start from here. Find your min and max dates for specific job.
FindMinMax = Table.AddColumn(DefaultDataTypes, "Custom", each
let
getJobs = [Job Name],
selectJobs = Table.SelectRows(DefaultDataTypes, each ([Job Name] = getJobs)),
minMax = Table.Group(selectJobs, {"Job Name"}, { {"Start Job Duration", each List.Min([Start Date]), type nullable date}, {"End Job Duration", each List.Max([End Date]), type nullable date} })
in
minMax
),
// expand
ExpandMinMax = Table.ExpandTableColumn(FindMinMax, "Custom", {"Start Job Duration", "End Job Duration"}, {"Start Job Duration", "End Job Duration"}),
ChangeDateType = Table.TransformColumnTypes(ExpandMinMax,{{"Start Job Duration", type date}, {"End Job Duration", type date}})
in
ChangeDateType
Here's the output of that:
EDIT: Attaching sample pbix just in case.
Hi @Afiq_Danial ,
You may try this sample:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsxLqVTSUfLKT1JwBNKGBvrG+kYGRkZQtiGEE6sTreRUVJmYh6rUEEmpoQlCqXNGTn4qqlIjJKVGSKYGJxYlZkCVOoGkDfXN4UoN9Y0NEEq9EnNTi1GVGhgjqUV2gWNxRk5qJZpiSyTFcDfEAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Staff Name" = _t, #"Job Name" = _t, #"Start Date" = _t, #"End Date" = _t]),
DefaultDataTypes = Table.TransformColumnTypes(Source,{{"Start Date", type date}, {"End Date", type date}}),
// start from here. Find your min and max dates for specific job.
FindMinMax = Table.AddColumn(DefaultDataTypes, "Custom", each
let
getJobs = [Job Name],
selectJobs = Table.SelectRows(DefaultDataTypes, each ([Job Name] = getJobs)),
minMax = Table.Group(selectJobs, {"Job Name"}, { {"Start Job Duration", each List.Min([Start Date]), type nullable date}, {"End Job Duration", each List.Max([End Date]), type nullable date} })
in
minMax
),
// expand
ExpandMinMax = Table.ExpandTableColumn(FindMinMax, "Custom", {"Start Job Duration", "End Job Duration"}, {"Start Job Duration", "End Job Duration"}),
ChangeDateType = Table.TransformColumnTypes(ExpandMinMax,{{"Start Job Duration", type date}, {"End Job Duration", type date}})
in
ChangeDateType
Here's the output of that:
EDIT: Attaching sample pbix just in case.
Thank you so much, it works! Appreciate it
User | Count |
---|---|
106 | |
89 | |
81 | |
76 | |
73 |
User | Count |
---|---|
112 | |
104 | |
96 | |
74 | |
66 |