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
Cocotip926
Frequent Visitor

calculate category total in table visualization

My source table 'Info' has several columns, [Client], [Country], [Year], [ProductCode] and [InvestAmount]. One client invest in several products, one client belongs to one country. Two years 2017 and 2018 are in the table. Now I created a table visualization using [Client], [Country], [Year] and [InvestAmount]. This visualization automatically aggregates InvestAmount on Client, so that every client is distinct in it.

Now I want to create a measure that aggregates InvestAmount on Country, and add this measure to the table visualization, so that every row with the same Country value displays same InvestAmount. I wrote the measure as:

[Country Total] = CALCULATE( SUM('Info'[InvestAmount]), ALLSELECTED('Info'[Country]))

It did not give the desired result, but expanded the table by adding extra rows, i.e combinations of each client with every countries.

What's wrong with my measure, please?

1 ACCEPTED SOLUTION

Hi @Cocotip926,

 

I made one sample based on your data. Actually you can upload the file you want to share to dorop box and share the link here.

 

1. Enter the data as you shared and create the relationship between the two tables.

 

Capture.PNG

 

2. create a calculated column based on the info table.

 

CN = RELATED(Country[Country_Name])

 

3. Create the measure to get the result as you excepted.

 

Measure = CALCULATE(SUM(Info[Invest_Amount]),ALLEXCEPT(Info,Info[CN]))

2.PNG

 

For more details, please check the pbix as attached.

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

4 REPLIES 4
v-frfei-msft
Community Support
Community Support

Hi @Cocotip926,

 

Please try to use this formula. If it doesn't meet your requirement, kindly share your sample data and excepted reuslt to me.

 

[Country Total] = CALCULATE( SUM('Info'[InvestAmount]), ALLSELECTED('Info'))

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Thank you! I didn't mention one thing. I have two tables, the other is a 'Country' table. 'Info' and 'Country' are related by [Country_Code]. I'm creating the table visualization with the two tables. Please take a look at the screenshots of my tables and report. (Don't know how to upload the whole file)

Country.PNGInfo.PNGReport.PNG

 

I'm trying to add the measure "Country Total" to my visualization, so that it can display the total investment amount for each country regardless of client.

eg. For both product A and E rows (both come from Argentina), in Country Total column, they should display 67. But using the measure 

Spoiler
Country Total = CALCULATE(SUM(Info[Invest_Amount]),ALLSELECTED(Country))

The visualization is displayed like this:

Table visualization.PNG

Thanks!


Hi @Cocotip926,

 

I made one sample based on your data. Actually you can upload the file you want to share to dorop box and share the link here.

 

1. Enter the data as you shared and create the relationship between the two tables.

 

Capture.PNG

 

2. create a calculated column based on the info table.

 

CN = RELATED(Country[Country_Name])

 

3. Create the measure to get the result as you excepted.

 

Measure = CALCULATE(SUM(Info[Invest_Amount]),ALLEXCEPT(Info,Info[CN]))

2.PNG

 

For more details, please check the pbix as attached.

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Thank you so much! It works! But could you please explain why do I need this new "related" column? I already have the relationship defined between tables. Thanks!

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.