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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Solution Authors
Top Kudoed Authors