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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
mason23
Helper I
Helper I

Create a measure to calculate SUM from two different table

Hi, I'll try my best to explain what I need to solve my problem. I have two tables (table1, table2) below. I have a created a relationship between the two tables using the location column. I'm using a stacked bar chart for the visual. What is the best approach to get the right result? Thanks for all your help!

 

Table 1

LocationNameCapacity
AApple100
BOrange75
CBanana95
DPear100

 

Table 2

Location# of Volunteers
A56
B15
C42
D50

 

mason23_1-1701396976104.png

 

 

 

3 ACCEPTED SOLUTIONS
123abc
Community Champion
Community Champion

Create a New Measure: Open the Power BI Desktop, go to the modeling tab, and click on "New Measure". Then, use the following DAX expression:

 

Total Capacity = SUM('Table1'[Capacity])

 

  1. This measure will give you the total capacity from Table1.

  2. Create Another Measure: Similarly, create a measure for the total number of volunteers:

Total Volunteers = SUM('Table2'[# of Volunteers])

 

  1. This measure will give you the total number of volunteers from Table2.

  2. Create a Stacked Bar Chart: Now, you can use these measures in your stacked bar chart. Place the "Location" field from either Table1 or Table2 on the axis, and then add the "Total Capacity" and "Total Volunteers" measures to the Values section of the chart.

    This will give you a visual representation of the total capacity and total number of volunteers for each location.

In summary, the key is to create measures that calculate the total capacity and total number of volunteers separately for each table and then use these measures in your visualizations.

 

OR

Try This measure also:
Total Capacity = SUMX(
table1,
table1[Capacity]
) + SUMX(
table2,
table2[# of Volunteers]
)

This measure will sum the Capacity column from table1 and the # of Volunteers column from table2. The SUMX function iterates over each row of the table and returns the sum of the expression for each row. In this case, the expression is simply the name of the column we want to sum.

I hope this helps! Let me know if you have any other questions.

 

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

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

 

 

View solution in original post

v-zhangti
Community Support
Community Support

Hi, @mason23 

 

Maybe there is no need to create measure.

vzhangti_0-1701676594734.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

View solution in original post

mason23
Helper I
Helper I

Thank you for your quick response. I tried both methods and it worked. 

View solution in original post

3 REPLIES 3
mason23
Helper I
Helper I

Thank you for your quick response. I tried both methods and it worked. 

v-zhangti
Community Support
Community Support

Hi, @mason23 

 

Maybe there is no need to create measure.

vzhangti_0-1701676594734.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

123abc
Community Champion
Community Champion

Create a New Measure: Open the Power BI Desktop, go to the modeling tab, and click on "New Measure". Then, use the following DAX expression:

 

Total Capacity = SUM('Table1'[Capacity])

 

  1. This measure will give you the total capacity from Table1.

  2. Create Another Measure: Similarly, create a measure for the total number of volunteers:

Total Volunteers = SUM('Table2'[# of Volunteers])

 

  1. This measure will give you the total number of volunteers from Table2.

  2. Create a Stacked Bar Chart: Now, you can use these measures in your stacked bar chart. Place the "Location" field from either Table1 or Table2 on the axis, and then add the "Total Capacity" and "Total Volunteers" measures to the Values section of the chart.

    This will give you a visual representation of the total capacity and total number of volunteers for each location.

In summary, the key is to create measures that calculate the total capacity and total number of volunteers separately for each table and then use these measures in your visualizations.

 

OR

Try This measure also:
Total Capacity = SUMX(
table1,
table1[Capacity]
) + SUMX(
table2,
table2[# of Volunteers]
)

This measure will sum the Capacity column from table1 and the # of Volunteers column from table2. The SUMX function iterates over each row of the table and returns the sum of the expression for each row. In this case, the expression is simply the name of the column we want to sum.

I hope this helps! Let me know if you have any other questions.

 

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

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

 

 

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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