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
PatrickH
Regular Visitor

Grouping two columns with same data (for a stacked column chart)

Hello everyone,

 

I am new to Power BI and I am currently working on a stacked column chart. I believe that the data I am using is not structured correctly for the chart to work as intended. That is why I am looking for a way to group two columns into one like in this example I made in Excel:

 

ExampleExample

The goal of the chart is to compare the Planned and Committed Hours for each phase.

 

I tried to look for solutions on how to these changes in Power BI but could not manage to make it work.

 

Let me know if you need further information. Thanks for the help!

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

Refer if this can help: https://radacad.com/pivot-and-unpivot-with-power-bi

Else Try to create a table like this and rename columns later

 

new table =
union(
summarize(table,name,table[commitment_phase1],table[commitment_phase2],"commitment/planned","commitment"),
summarize(table,name,table[planned phase 1],table[planned phase2],"commitment/planned","planned")
)

 

OR

new table =
union(
selectcolumns(table,name,"Phase 1" ,table[commitment_phase1],"Phase 2",table[commitment_phase2],"commitment/planned","commitment"),
selectcolumns(table,name,"Phase 1",table[planned phase 1],"Phase 2",table[planned phase2],"commitment/planned","planned")
)

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Proud to be a Datanaut Connect on Linkedin

 

View solution in original post

Pragati11
Super User
Super User

Hi @PatrickH ,

 

I tried with your sample data and was able to do it in Edit Query in Power BI as follows:

Plan1.png

 

Select the columns as shown below and click on the drop-down again "Unpivot Columns" and select "Unpivot Only Selected Columns"

 

Plan2.png

You get the following:

Plan3.png

Duplicate the "Attribute" column as shown and click on "Extract" option as shown below:

 

Plan4.png

 
 

Give a character space in the dialog below and click OK:

Plan5.png

 You see the following:

Plan6.png

Rename this column to "Phase" as shown below:

Plan7.png

 

Select "Attribute" column as shown below and give space character and hit OK to the dialog box similar to we did above: 

Plan8.png

 

You will get the following:

Plan9.png

 

Now comes the final step where we will use Group BY functionality on "Phase" column. 

Plan10.png

You will see following dialog box appearing. Give the settings as shown below:

Plan11.png

 

You will get following output:

Plan12.png

 Click on the icon highlighted above and you get following:

Plan13.png

 

After Clicking OK, you get the following:

Pkan14.png

 

Remove the 1st "Phase" column as highlighted above and rename rest of the other columns as required. You will get the following:

Plan15.png

 

Last Step Finally. Select "Phase" column and click "Pivot Column" as highlighted in above picture. A dialog appears as follows. Make sure to select "Value" column here because we want it on this column and hit Ok. We get the desired result:

Plan16.png

 

Plan17.png

 

Hope this helps. 🙂

 

Please mark this as a solution if it works for you!

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

View solution in original post

3 REPLIES 3
Pragati11
Super User
Super User

Hi @PatrickH ,

 

I tried with your sample data and was able to do it in Edit Query in Power BI as follows:

Plan1.png

 

Select the columns as shown below and click on the drop-down again "Unpivot Columns" and select "Unpivot Only Selected Columns"

 

Plan2.png

You get the following:

Plan3.png

Duplicate the "Attribute" column as shown and click on "Extract" option as shown below:

 

Plan4.png

 
 

Give a character space in the dialog below and click OK:

Plan5.png

 You see the following:

Plan6.png

Rename this column to "Phase" as shown below:

Plan7.png

 

Select "Attribute" column as shown below and give space character and hit OK to the dialog box similar to we did above: 

Plan8.png

 

You will get the following:

Plan9.png

 

Now comes the final step where we will use Group BY functionality on "Phase" column. 

Plan10.png

You will see following dialog box appearing. Give the settings as shown below:

Plan11.png

 

You will get following output:

Plan12.png

 Click on the icon highlighted above and you get following:

Plan13.png

 

After Clicking OK, you get the following:

Pkan14.png

 

Remove the 1st "Phase" column as highlighted above and rename rest of the other columns as required. You will get the following:

Plan15.png

 

Last Step Finally. Select "Phase" column and click "Pivot Column" as highlighted in above picture. A dialog appears as follows. Make sure to select "Value" column here because we want it on this column and hit Ok. We get the desired result:

Plan16.png

 

Plan17.png

 

Hope this helps. 🙂

 

Please mark this as a solution if it works for you!

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Hi @PatrickH ,

 

Kindly mark this as a solution if it worked 🙂

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

amitchandak
Super User
Super User

Refer if this can help: https://radacad.com/pivot-and-unpivot-with-power-bi

Else Try to create a table like this and rename columns later

 

new table =
union(
summarize(table,name,table[commitment_phase1],table[commitment_phase2],"commitment/planned","commitment"),
summarize(table,name,table[planned phase 1],table[planned phase2],"commitment/planned","planned")
)

 

OR

new table =
union(
selectcolumns(table,name,"Phase 1" ,table[commitment_phase1],"Phase 2",table[commitment_phase2],"commitment/planned","commitment"),
selectcolumns(table,name,"Phase 1",table[planned phase 1],"Phase 2",table[planned phase2],"commitment/planned","planned")
)

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Proud to be a Datanaut Connect on Linkedin

 

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.