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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
nh27
Helper III
Helper III

Help creating a stacked chart by multiple columns

Hi, I am trying to create a stacked bar chart which shows 4 products currently split by column and there are different phases of the product. I have attached sample data and expected output.

Is there any way to achieve this without having to unpivot the data?image.jpgproductsampledata.png

The challenge I have is the data is already gone through ETL but due to new requirements need to make this work. Am I better off creating a reference query and carry out the unpivot transformation there?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @nh27 ,

 

I made a sample for you with dax.

vxiaocliumsft_0-1729045520885.png

vxiaocliumsft_1-1729045542356.png

vxiaocliumsft_3-1729045726718.png

 

vxiaocliumsft_2-1729045574928.png

 

Measure = SWITCH(SELECTEDVALUE('Table'[Value]),
"Product A",COUNTROWS(FILTER('Table1',NOT(ISBLANK([Product A])))),
"Product B",CALCULATE( COUNTROWS(FILTER('Table1',NOT(ISBLANK([Product B])))),USERELATIONSHIP(Table1[Product B],'Table 2'[Value])),
"Product C",CALCULATE( COUNTROWS(FILTER('Table1',NOT(ISBLANK([Product C])))),USERELATIONSHIP(Table1[Product C],'Table 2'[Value])),
"Product D",CALCULATE( COUNTROWS(FILTER('Table1',NOT(ISBLANK([Product D])))),USERELATIONSHIP(Table1[Product D],'Table 2'[Value]))
)

 

 

Best Regards,

Wearsky

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @nh27 ,

 

I made a sample for you with dax.

vxiaocliumsft_0-1729045520885.png

vxiaocliumsft_1-1729045542356.png

vxiaocliumsft_3-1729045726718.png

 

vxiaocliumsft_2-1729045574928.png

 

Measure = SWITCH(SELECTEDVALUE('Table'[Value]),
"Product A",COUNTROWS(FILTER('Table1',NOT(ISBLANK([Product A])))),
"Product B",CALCULATE( COUNTROWS(FILTER('Table1',NOT(ISBLANK([Product B])))),USERELATIONSHIP(Table1[Product B],'Table 2'[Value])),
"Product C",CALCULATE( COUNTROWS(FILTER('Table1',NOT(ISBLANK([Product C])))),USERELATIONSHIP(Table1[Product C],'Table 2'[Value])),
"Product D",CALCULATE( COUNTROWS(FILTER('Table1',NOT(ISBLANK([Product D])))),USERELATIONSHIP(Table1[Product D],'Table 2'[Value]))
)

 

 

Best Regards,

Wearsky

Thank you very much, this worked a charm!

rajendraongole1
Super User
Super User

Hi @nh27 - You can create a reference query and then apply the unpivot operation like this:

  • Go to Transform Data.
  • Right-click your query and choose Reference.
  • In the new reference query, select the columns that represent the phases and choose Unpivot Columns.

This will give you a more dynamic and flexible structure, where phases are represented in a single column, and you can easily build stacked bar charts based on these dynamically.

pls check and let know if it works.





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

Proud to be a Super User!





Hi, thanks for this. I have already test this method and it worked, just wasn't sure if there was another way to do this via DAX Measures and whatnot.

create separate measure for each phase in Power BI as like below:

Phase1_Measure = SUM(Products[Phase1])
Phase2_Measure = SUM(Products[Phase2])
Phase3_Measure = SUM(Products[Phase3])





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

Proud to be a Super User!





Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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