The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
I have a table with project names, a date column, and some other columns. I am trying to create a query that produces a table with projects and their start and end dates.
Start date defined as the earliest date in a column of dates, for a given project.
End date defined as latest date in, the same column of dates, for a given project.
My sample data is below. I couldn't figure out how to attach the file here.
The projects are listed multiple times. I think I need to copy the query, rename it min date, loop through the list of projects and find the earliest date earliest date. Do the same for latest date. I'm stuck on trying to get the dates linked back to a single project. I don't know how to deal with the duplicate projects.
I found this method but can't get it to account for the duplicate projects. https://www.myonlinetraininghub.com/extract-start-and-end-dates-with-power-query
Trying to get a query that produces something like this:
Project | Start Date | End Date |
Sample data (there are thousands of rows, this is only a subset):
Project | Milestone | Resource | Date | Hours | Index |
Project C | Malick, Martin | 8/3/2020 | 225 | 759 | |
Project A | Malick, Martin | 8/10/2020 | 225 | 760 | |
Project C | Blue, Steph | 8/17/2020 | 225 | 761 | |
Project C | Blue, Steph | 8/24/2020 | 225 | 762 | |
Project B | Blue, Steph | 8/31/2020 | 224 | 433 | |
Project A | Milestone 2 | 9/7/2020 | 212 | 764 | |
Project C | Blue, Steph | 9/21/2020 | 212 | 766 | |
Project C | Blue, Steph | 10/5/2020 | 210 | 768 | |
Project C | Fanny, Pack | 8/31/2020 | 209 | 763 | |
Project B | Milestone 1 | 9/7/2020 | 202 | 434 | |
Project B | Fanny, Pack | 8/17/2020 | 198 | 431 | |
Project A | 9/14/2020 | 195 | 765 | ||
Project B | Malick, Martin | 8/10/2020 | 192 | 430 | |
Project C | Fanny, Pack | 9/28/2020 | 192 | 767 | |
Project A | Field, Sally | 10/12/2020 | 185 | 769 |
Solved! Go to Solution.
Power Query:
// output
let
Source = Table.FromRecords(Json.Document(Binary.Decompress(Binary.FromText("rZRLa4QwFIX/imQdMInPuKstQ7sQhnZZuwhOoHZCLD6gQ5n/3khfsTHaCe5iCHyec+65j+9g3zYvvOpB9n3yrgEERS141zeSg0wOQkBwz7tmaCv1DQom6uoIvYK1fS3V4xvWj/dp6QelTxBB6u5Wve5ARkgEwZ088DeQJRE9wznglTsQo0VijOaJaxJzMXDoPfT89XmKS5ZxeFscCZdxZB6XO+ICbOLCH1wYBP+K7/fsEaBzP//jC0dL3/QSE01cuKGXikZMcRNcvCFunMrIxCENl7rhdkzKE/T2rDquRYeohrNEl1ujwxdGh4g2KJbo1ubSJs5sHaaphrO0bmWt/NWEjbJhqpctchN10fLCVLfRcXnN2jg2IF3CJXHitp13NRcHVQEmxGlaAUwMYKo7Ss9PHw==",BinaryEncoding.Base64),Compression.Deflate))),
chtype = Table.TransformColumnTypes(Source,{{"Date", type date}}),
group = Table.Group(chtype, {"Project"}, {{"Start Date", each List.Min([Date]), type date},{"End Date", each List.Max([Date]), type date}})
in
group
Power Query:
// output
let
Source = Table.FromRecords(Json.Document(Binary.Decompress(Binary.FromText("rZRLa4QwFIX/imQdMInPuKstQ7sQhnZZuwhOoHZCLD6gQ5n/3khfsTHaCe5iCHyec+65j+9g3zYvvOpB9n3yrgEERS141zeSg0wOQkBwz7tmaCv1DQom6uoIvYK1fS3V4xvWj/dp6QelTxBB6u5Wve5ARkgEwZ088DeQJRE9wznglTsQo0VijOaJaxJzMXDoPfT89XmKS5ZxeFscCZdxZB6XO+ICbOLCH1wYBP+K7/fsEaBzP//jC0dL3/QSE01cuKGXikZMcRNcvCFunMrIxCENl7rhdkzKE/T2rDquRYeohrNEl1ujwxdGh4g2KJbo1ubSJs5sHaaphrO0bmWt/NWEjbJhqpctchN10fLCVLfRcXnN2jg2IF3CJXHitp13NRcHVQEmxGlaAUwMYKo7Ss9PHw==",BinaryEncoding.Base64),Compression.Deflate))),
chtype = Table.TransformColumnTypes(Source,{{"Date", type date}}),
group = Table.Group(chtype, {"Project"}, {{"Start Date", each List.Min([Date]), type date},{"End Date", each List.Max([Date]), type date}})
in
group
Thank you!
Oh yeah, Power Query, I always forget to check which forum things are in!
@bucket - This should be something like:
Table =
SUMMARIZE('Table',[Project],"Start Date",MIN('Table'[Date]),"End Date",MAX('Table'[Date]))
I think the tutorial you've been looking at will leave you more confused.
In Power Query, select the 'Group By' from the ribbon.
Click Advanced.
Put Project in the groupby field.
Use 2 aggregations, both on the Date column : one will be 'startDate' for column name, Operation : Min
one will be 'endDate' for column name, Operation : Max
good luck.
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.