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

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.

Reply

Pivot or unpivot Multiple Columns

Hi Everyone,  

I am very new to Power Query, and I am looking for a solution to pivot or unpivot data into tabular format.

I believe someone can very quickly help me.

Note: The prgrs break down name will change ID by ID.

Sample Excel file ajisharavind_99_0-1687347731390.png

 

1 ACCEPTED SOLUTION
slorin
Super User
Super User

Hi,

 

= Table.FromRows(
List.TransformMany(
Table.ToRows(Previous_Step),
each {0..6},
(x,y) => {x{0}, x{1+y}, x{8+y}, x{15+y}, x{22+y}, x{29+y}, x{35+y}, x{42+y}}
),
type table [ID = text, Prgrs Breack Down = text, Actual = number, Approved Plan = number, Current Plan= number, Int Plan = number, QPIT VAR = number, Var = number]
)

 

Stéphane 

View solution in original post

4 REPLIES 4
slorin
Super User
Super User

Hi,

 

= Table.FromRows(
List.TransformMany(
Table.ToRows(Previous_Step),
each {0..6},
(x,y) => {x{0}, x{1+y}, x{8+y}, x{15+y}, x{22+y}, x{29+y}, x{35+y}, x{42+y}}
),
type table [ID = text, Prgrs Breack Down = text, Actual = number, Approved Plan = number, Current Plan= number, Int Plan = number, QPIT VAR = number, Var = number]
)

 

Stéphane 

@slorin Thank you very much 🙂 working well , Colud you explain how this code is working (for my understanding)

Hi,

 

Table.ToRows(Previous_Step) 

--> x = each row of Previous_Step (x is a list)

 

each {0..6} 

--> y = 0 ,  y = 1, .... y = 6

 

(x,y) => {x{0}, x{1+y}, x{8+y}, x{15+y}, x{22+y}, x{29+y}, x{35+y}, x{42+y}}

x = first row and  y = 0 

 {x{0} <=> ID, x{1+0} <=> StageDesc1, x{8+0}<=>Actual1, x{15+0}<=>AprvdPlan1 ...}

 

next x = first row and y = 1

{ x{0} <=> ID, x{1+1} <=> StageDesc2, x{8+1}<=>Actual2, x{15+1}<=>AprvdPlan2 ...}

...

List.TransformMany split all rows into 7 lists ( y = 0 to y = 6)

 

and Table.FromRows build a table with this list of list

 

Stéphane

Thank you very much for your time for explaining the code

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.

Top Solution Authors
Top Kudoed Authors