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 Transpose Table using DAX rather than Power Query

Hi Everyone,

I have Table 1 (below) which was created using the DAX GENERATE function.  I now need to pivot this table to adjust the columns (Table 2).  Normally I'd perform this operation in Power Query using the Pivot function however I don't believe it's possible to make Power Query adjustments on a table if it's been generated in DAX (if so please provide more information).  

I understand from the forum posts below that there is a solution using Summarize and potentially Union however for the life of me I'm not able to figure it out. Any assistance is greatly appreciated.

 

Table 1: Raw Data (roughly 100k rows, 10 columns in actual dataset)

IndexAmountDateLocation
15001/1/2020Australia
22001/2/2020Canada
320001/3/2020UK
220001/4/2020Australia
345001/5/2020USA
11001/6/2020Canada
13001/4/2020UK
150001/6/2020China
240001/6/2020Australia
22001/2/2020UK
230001/1/2020China
320001/1/2020Australia
13001/1/2020USA
150001/2/2020Canada
140001/3/2020UK
13001/4/2020Australia
150001/5/2020USA
140001/6/2020Canada
12001/4/2020UK
130001/6/2020China
120001/6/2020Australia
120001/2/2020USA
23001/1/2020Australia
250001/1/2020Canada
240001/1/2020UK
23001/2/2020Australia
250001/3/2020USA
220001/4/2020Canada
23001/5/2020UK
250001/6/2020China
240001/4/2020Australia
23001/1/2020UK
350001/2/2020China
340001/3/2020Australia
320001/4/2020USA
33001/5/2020Canada
350001/6/2020UK
340001/4/2020Australia
33001/6/2020USA
350001/6/2020Canada
340001/2/2020UK
32001/1/2020China
330001/1/2020Australia

 

Table 2: Transformed Data(roughly 50 rows, 2k columns. Columns will likely be filtered down to 200-300)

DateLocation123
1/01/2020Australia5003005000
1/01/2020Canadanull5000null
1/01/2020Chinanull3000200
1/01/2020UKnull4300null
1/01/2020USA300nullnull
1/02/2020Australianull300null
1/02/2020Canada5000200null
1/02/2020Chinanullnull5000
1/02/2020UKnull2004000
1/02/2020USA2000nullnull
1/03/2020Australianullnull4000
1/03/2020UK4000null2000
1/03/2020USAnull5000null
1/04/2020Australia30060004000
1/04/2020Canadanull2000null
1/04/2020UK500nullnull
1/04/2020USAnullnull2000
1/05/2020Canadanullnull300
1/05/2020UKnull300null
1/05/2020USA5000null4500
1/06/2020Australia20004000null
1/06/2020Canada4100null5000
1/06/2020China80005000null
1/06/2020UKnullnull5000
1/06/2020USAnullnull300

 

Example visualisations to be created:

2021-02-22_18-30-31.png2021-02-22_18-30-52.png

Example Power BI file:

https://drive.google.com/file/d/1i445hX9IAD5PoTWmVrAn9BDVl_dj7mSg/view?usp=sharing 

Similiar issues that have happened to others

Cheers,

Campbell

1 ACCEPTED SOLUTION

Hi @campbellmurphy 

 

Looking at your updated information you don't need to pivot the information, if you use the Index column on the legend of the visualizatiions and change the X-axis according to your needs you can do it has you need, further more yoiu can create an hierarchy with the index and location.

 

Or do you have some other needs in terms of visualization that is not explained in the example you have?

 

MFelix_0-1613986617594.png

I used a slicer to filter information by index.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

5 REPLIES 5
mahoneypat
Employee
Employee

In general, you should not pivot your data like this.  Please describe/show your desired final visual that you believe requires this format, so that an alternate approach can potentially be suggested.

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hey @mahoneypat,

Thanks for the feedback.  I've updated my original post and the associated example power bi file. The most obvious alternative solution I can think of is to use ADDCOLUMNS when creating a new table within DAX with each new column being filtered for a particular index. This doesn't scale well over 1000 columns which are likely to change into the future though. Your feedback is greatly appreciated.

Cheers,

Campbell 

Hi @campbellmurphy 

 

Looking at your updated information you don't need to pivot the information, if you use the Index column on the legend of the visualizatiions and change the X-axis according to your needs you can do it has you need, further more yoiu can create an hierarchy with the index and location.

 

Or do you have some other needs in terms of visualization that is not explained in the example you have?

 

MFelix_0-1613986617594.png

I used a slicer to filter information by index.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



MFelix
Super User
Super User

Hi @campbellmurphy ,

 

Do you just want to present the information has you have it in the last image? or can it be a little bit different?

 

If it can have a slitgh  look and fell use a matrix visualization something similar to this:

 

MFelix_0-1613754490596.png

 

If you want the exaxt look and fell you can try and do what is in this blog post:

 

https://businessintelligist.com/2020/07/27/power-bi-dax-tutorial-how-to-pivot-data-using-dax-using-r...

 

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @MFelix ,

 

I want the data transformed as it is in the image e.g. in a new table (not a matrix) as I need to use each of the new index column numbers as unique variables in visualisations. 

 

The blog post provided manually creates each column which I'd strongly prefer not to do as I'd have 2000 columns which may change data sources over time.

 

Thanks,

 

Campbell

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.