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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.