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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
ChrisR22
Helper III
Helper III

Quarterly Columns to Date

Hello,

 

I currently have data regularly coming to me in the format 

GroupQ1Q2Q3Q4

Alpha

$50,000$45,000$45,000$90,000
Beta$25,000$49,000$71,000$38,000
Gamma$88,000$68,000$57,000$63,000

 

Because of this format I cannot build charts or slicers based on the time (quater) because they are in separate columns. Does anyone have a good method of applied steps or DAX formulas that can automatically transform my dataset into the following format

 

GroupQuarterRevenue
AlphaQ1$50,000
AlphaQ2$45,000
AlphaQ3$45,000

... and so on. In addition to revenue there are also separate data tables for headcount and targets that also arrive in this format. Ideally I'd like to be able to apply the transformations to all three incoming data tables at once to get something like:

GroupQuarterRevenueHeadcountTarget
AlphaQ1$50,00050$48,000
AlphaQ2$45,00052$47,000

 

I can use an unpivot function in Power Query, but there are two issues with that:

1. unpivoting multiple bunches of quater columns (i.e. the 4 columns for revenue and the 4 colums for headcount) return more than 4 rows, in fact it returns 8. I'd need them all consolidated into 4 rows, one for each quarter.

2. I cannot figure out how to make that automatically apply outside of building a macro, which in itself is a manual process as someone would have to run it each time data was provided.

 

Alternatively, if someone has a good method to be able to call the quarter field out in visuals without having to transform the data that would be sufficient.

 

Thanks in advance!

1 ACCEPTED SOLUTION
Ritaf1983
Super User
Super User

Hi @ChrisR22 

The most efficient way to transform your tables is definitely through Power Query (PQ). The fact that the number of rows increases after unpivoting shouldn’t be a concern because once you aggregate the data in DAX, everything will be summarized based on the level of granularity in your visualizations. Also, there’s no need for a macro because Power Query steps are recorded and automatically repeat every time you refresh the data.

Here’s how you can approach this:

  1. Unpivoting the Data:

    • In Power Query, select the columns for each quarter (e.g., Q1, Q2, Q3, Q4), and use the "Unpivot" option to turn these columns into rows. This will create a column for Quarter and another one for the Revenue (or other metrics like Headcount and Target).
  2. Combining Multiple Data Tables:

    • To handle multiple data tables like Revenue, Headcount, and Target, you can unpivot each table individually and then merge them on the Group and Quarter columns. This way, you’ll end up with a combined table that has Group, Quarter, Revenue, Headcount, and Target in a single structure.
  3. No Manual Macro Needed:

    • Power Query automatically applies the transformations when refreshing the data, so there’s no need to build or run a macro. This ensures that every time new data arrives, it’s automatically transformed without any manual intervention.
  4. Using a Date Table (For Larger Datasets):

    • If your dataset is large or spread across multiple tables, it might make sense to use a Date Table to link all the data tables together. This allows for easier management of Quarter data, helps align time intelligence functions, and improves performance. By creating relationships between your Revenue, Headcount, and Target tables with the Date Table, you can manage large datasets more effectively.

By following this approach, you can avoid the issues you mentioned, keep the data transformation automated, and build dynamic reports with a flexible structure. Also, using a Date Table will help you work efficiently with larger datasets, allowing you to scale without manual workarounds.

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

1 REPLY 1
Ritaf1983
Super User
Super User

Hi @ChrisR22 

The most efficient way to transform your tables is definitely through Power Query (PQ). The fact that the number of rows increases after unpivoting shouldn’t be a concern because once you aggregate the data in DAX, everything will be summarized based on the level of granularity in your visualizations. Also, there’s no need for a macro because Power Query steps are recorded and automatically repeat every time you refresh the data.

Here’s how you can approach this:

  1. Unpivoting the Data:

    • In Power Query, select the columns for each quarter (e.g., Q1, Q2, Q3, Q4), and use the "Unpivot" option to turn these columns into rows. This will create a column for Quarter and another one for the Revenue (or other metrics like Headcount and Target).
  2. Combining Multiple Data Tables:

    • To handle multiple data tables like Revenue, Headcount, and Target, you can unpivot each table individually and then merge them on the Group and Quarter columns. This way, you’ll end up with a combined table that has Group, Quarter, Revenue, Headcount, and Target in a single structure.
  3. No Manual Macro Needed:

    • Power Query automatically applies the transformations when refreshing the data, so there’s no need to build or run a macro. This ensures that every time new data arrives, it’s automatically transformed without any manual intervention.
  4. Using a Date Table (For Larger Datasets):

    • If your dataset is large or spread across multiple tables, it might make sense to use a Date Table to link all the data tables together. This allows for easier management of Quarter data, helps align time intelligence functions, and improves performance. By creating relationships between your Revenue, Headcount, and Target tables with the Date Table, you can manage large datasets more effectively.

By following this approach, you can avoid the issues you mentioned, keep the data transformation automated, and build dynamic reports with a flexible structure. Also, using a Date Table will help you work efficiently with larger datasets, allowing you to scale without manual workarounds.

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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

Top Kudoed Authors