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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
rossmccoriston
Regular Visitor

Pivot within a pivot

Hi,

 

I have the following example dataset:

NameTask DaysDay
1A101/01/2020
1A102/01/2020
1B103/01/1900
1B104/01/2020
1B105/01/2020
2A101/01/2020
2A102/01/2020
2B103/01/1900
2B104/01/2020
2B1

05/01/2020

 

I am trying to achieve something similar to the below:

 

NameTask DaysWeek
1A201/01/2020
1B301/01/2020
2A201/01/2020
2B301/01/2020
1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi @rossmccoriston , 

I am not sure whether "03/01/1900" is mis-writing? If so, you also could refer to below M code for details.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIEYhBtYKgPREYGRgZKsTpoUkYYUk4wKWPcUia4pUxRpIxwO8MItzOMcDvDCLczjHA4IxYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Name = _t, #"Task " = _t, Days = _t, Day = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", Int64.Type}, {"Task ", type text}, {"Days", Int64.Type}, {"Day", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Name"}, {{"minDay", each List.Min([Day]), type date}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Name"}, #"Grouped Rows", {"Name"}, "Grouped Rows", JoinKind.RightOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"minDay"}, {"minDay"}),
    #"Grouped Rows1" = Table.Group(#"Expanded Grouped Rows", {"Name", "Task "}, {{"Count", each Table.RowCount(_), type number}, {"min", each List.Min([minDay]), type date}})
in
    #"Grouped Rows1"

Best Regards,
Zoe Zhi

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

3 REPLIES 3
dax
Community Support
Community Support

Hi @rossmccoriston , 

I am not sure whether "03/01/1900" is mis-writing? If so, you also could refer to below M code for details.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIEYhBtYKgPREYGRgZKsTpoUkYYUk4wKWPcUia4pUxRpIxwO8MItzOMcDvDCLczjHA4IxYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Name = _t, #"Task " = _t, Days = _t, Day = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", Int64.Type}, {"Task ", type text}, {"Days", Int64.Type}, {"Day", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Name"}, {{"minDay", each List.Min([Day]), type date}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Name"}, #"Grouped Rows", {"Name"}, "Grouped Rows", JoinKind.RightOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"minDay"}, {"minDay"}),
    #"Grouped Rows1" = Table.Group(#"Expanded Grouped Rows", {"Name", "Task "}, {{"Count", each Table.RowCount(_), type number}, {"min", each List.Min([minDay]), type date}})
in
    #"Grouped Rows1"

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

negi007
Community Champion
Community Champion

@rossmccoristonin case you are looking to pivot mulitple times, you may have a look at below blog

 

https://kohera.be/blog/power-bi/how-to-unpivot-twice/

 

Else, please provide the output that you are looking for clearly. 

 




Did I answer your question? Mark my post as a solution!
Appreciate your Kudos



Proud to be a Super User!


Follow me on linkedin

AlB
Super User
Super User

Hi @rossmccoriston 

What is the logic for the last column?? Always 01/01/2020? If so:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIEYhBtYKgPREYGRgZKsTpoUkYYUk4wKWOQlKGlARYpE9y6TFGkjHA7wwi3M4xwO8MItzOMcDgjFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"Task " = _t, Days = _t, Day = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", Int64.Type}, {"Task ", type text}, {"Days", Int64.Type}, {"Day", type date}}),
    
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Name", "Task "}, {{"Days", each Table.RowCount(_), type number}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Week", each #date(2020,1,1), type date)
in
    #"Added Custom"

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors