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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

showing data in matrix

Im going to show numbers per company per week in a table or matrix, but the way the data shows is wrong. I want the weeks to be horizontaly and the companies to be vertically. right now in my queries i have one column with weeks, and the numbers for the companies in each column. Is there a way i can put all the columns as rows instead. I dont want to use transpose, since then the weeks will be as columns. What im basically looking for is a way to have one column with the names of the company, one column for the week the data is from, and one column with the data. What i have now is a column with weeks, and seperate columns for each company.

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

if I got you right you need the pivot-function. Check out this solution

let
	Source = #table
	(
		{"Company","Week","Value"},
		{
			{"A","Week 1","1"},	{"A","Week 2","2"},	{"A","Week 3","3"},	{"A","Week 4","4"},	{"B","Week 1","5"},	{"B","Week 2","6"},	{"B","Week 3","7"},	{"B","Week 4","8"},	
			{"B","Week 5","9"},	{"C","Week 1","10"},	{"C","Week 2","11"},	{"C","Week 3","12"},	{"C","Week 4","13"}
		}
	),
    ChangedType = Table.TransformColumnTypes(Source,{{"Value", Int64.Type}}),
    Pivot = Table.Pivot(ChangedType, List.Distinct(ChangedType[Week]), "Week", "Value", List.Sum)
in
    Pivot

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query or just select the week-column and select Transform -> Pivot column. In my solution i selected SUM for the aggregation. Change this if another calculation is needed (in case of multiple rows on Company/week-level.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

View solution in original post

3 REPLIES 3
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

if I got you right you need the pivot-function. Check out this solution

let
	Source = #table
	(
		{"Company","Week","Value"},
		{
			{"A","Week 1","1"},	{"A","Week 2","2"},	{"A","Week 3","3"},	{"A","Week 4","4"},	{"B","Week 1","5"},	{"B","Week 2","6"},	{"B","Week 3","7"},	{"B","Week 4","8"},	
			{"B","Week 5","9"},	{"C","Week 1","10"},	{"C","Week 2","11"},	{"C","Week 3","12"},	{"C","Week 4","13"}
		}
	),
    ChangedType = Table.TransformColumnTypes(Source,{{"Value", Int64.Type}}),
    Pivot = Table.Pivot(ChangedType, List.Distinct(ChangedType[Week]), "Week", "Value", List.Sum)
in
    Pivot

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query or just select the week-column and select Transform -> Pivot column. In my solution i selected SUM for the aggregation. Change this if another calculation is needed (in case of multiple rows on Company/week-level.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Anonymous
Not applicable

Hey @Jimmy801 

 

Thank you, I simply used the unpivit column function to fix it. But thanks for the help. 

Hello @Anonymous 

 

but this is exactly what I've written and showed you with the M-code

image.png

 

...

 

Jimmy

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors
Top Kudoed Authors