Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
100 | |
74 | |
63 | |
62 |
User | Count |
---|---|
143 | |
104 | |
103 | |
82 | |
66 |