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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Netrelemo
Helper IV
Helper IV

Ungroup a date grouing

I want to "ungroup" a dataset, but I don't know where to start using PowerQuery

I asked this question previously, got an answer, accepted it as a solution, but then found it didnt actually work.
https://community.powerbi.com/t5/Desktop/Ungroup-a-date-grouping/m-p/2377244#M854570
So I have asked this again.

In my raw dataset I have 7,500 rows.
After transformation, I expect to see a lot more than 7,500 rows.


Convert this: Activities by Financial Period with Start and End Date

ProjectID PhaseName FinPeriodStart FinPeriodFinish
AB315 Design 2022-06-30 2022-10-31
AB315 Implementation 2022-07-31 2022-09-30

 


To this: Activities by Financial Period

ProjectID FinPeriod Activities
AB315 2022-06-30 Design
AB315 2022-07-31 Design
AB315 2022-08-31 Design
AB315 2022-09-30 Design
AB315 2022-10-31 Design
AB315 2022-07-31 Implementation
AB315 2022-08-31 Implementation
AB315 2022-09-30 Implementation

 

And then, group by ProjectID and finPeriod

ProjectID FinPeriod Activities
AB315 2022-06-30 Design
AB315 2022-07-31 Design, Implementation
AB315 2022-08-31 Design, Implementation
AB315 2022-09-30 Design, Implementation
AB315 2022-10-31 Design

2 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

Thank you, much apreciated 

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you, much apreciated 

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
AlexisOlson
Super User
Super User

You can create a list of dates between start and end and pick just the month ends, then expand that list into new columns.

 

Here's how to construct the list:

AlexisOlson_0-1647555081459.png

 

Here's the full query you can paste into the Advanced Editor of a new blank query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnQyNjRV0lFySS3OTM8DMowMjIx0Dcx0jQ1gHEMDXWNDpVgdhGLP3IKc1NzUvJLEksx8hCZzkDoYxxJkQmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ProjectID = _t, PhaseName = _t, FinPeriodStart = _t, FinPeriodFinish = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ProjectID", type text}, {"PhaseName", type text}, {"FinPeriodStart", type date}, {"FinPeriodFinish", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Activities", each List.Select(List.Dates([FinPeriodStart], Duration.Days([FinPeriodFinish] - [FinPeriodStart]) + 1, #duration(1, 0, 0, 0)), each _ = Date.EndOfMonth(_) )),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"FinPeriodStart", "FinPeriodFinish"}),
    #"Expanded Activities" = Table.ExpandListColumn(#"Removed Columns", "Activities")
in
    #"Expanded Activities"

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.