Forum Discussion
Alternatives to Unpivot
Good Afternoon,
I am working with a dataset that started out with 30,000 rows. I had to unpivot 12 columns each representing a month with values in the rows. When I unpivoted those 12 month columns I now have 360,000 rows and it takes roughly 90 minuted to process that pivot with a direct dataverse connection to a dynamics 365 database.
I have created a representative (but much smaller) pbix for illustration purposes... The original query is what the data looks like before the unpivot. The sales query is the result of the unpivot.
I unpivoted as I needed to obtain sales by month and display in a visual like this (among others also doing month this year month last year)
I have attached the sample pbix here
My questions are:
Is there a better way than unpivot to isolate the months when there is a column for every month? I need to use the monthly figures in my visuals.
If not, is there anyway i can improve the refresh time. Even the calculated column I added to the larger data set took 90 minutes to process when I hit close and apply in the query editor. The sample dataset provided in this post of course processes quickly.
Thanks
P.S. I should also point out that the months and dates in the source data are of text type not date. They will not change to date type in power BI due to parsing errors.
Actually, you wouldn't need to unpivot, since breaking it into 12 queries (one per month) would effectively unpivot the table. You would need to add a column to each query for Month (in the Jan query, this column would be 1).
3 Replies
- DataInsights
Super User
You might try breaking this into 12 separate queries, one for each month. For the Jan query, you would delete columns Feb - Dec, and then unpivot. For the Feb query, you would delete columns Jan, Mar - Dec, and then unpivot. After repeating this for each month, append these 12 queries into one.
- DataInsights
Super User
Actually, you wouldn't need to unpivot, since breaking it into 12 queries (one per month) would effectively unpivot the table. You would need to add a column to each query for Month (in the Jan query, this column would be 1).
- juncco888
Advocate I
Thanks. This was something I had considered. Was hoping there was something I was missing about unpivot and its impact on performance in a direct query report. I apppreciate your assistance.
Thanks again!