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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
rnola16
Advocate II
Advocate II

Report Builder Total sum calculation on a column

I have a column in a tablix where the calculation is performed using multiple datasets using IIF function. I now have to create a Total Sum of that column. When I use the =Sum(IIF. (IIF(IIF Dataset1) Dataset2) Dataset3))....) it throws me an error. On searching more Co-pilot says that I cannot use aggregate function when using multiple datasets. How can I achieve this ?

 

Thanks.

1 ACCEPTED SOLUTION
burakkaragoz
Community Champion
Community Champion

Hi @rnola16 ,

 

You can't sum across multiple datasets in Report Builder - it's a known pain point that Microsoft never bothered to fix properly.

Real solutions that actually work:

Fix it at the source: Combine your datasets into one query with UNION or JOIN. Then you can use normal SUM() without the headache.

Custom code hack: Add this to Report Properties → Code:

Dim total As Decimal = 0
Public Function AddUp(val As Decimal) As Decimal
    total = total + val
    Return val
End Function
Public Function GetTotal() As Decimal
    Return total
End Function

In your cells: =Code.AddUp(your IIF mess) In total: =Code.GetTotal()

It's ugly but works.

Why this happens: Report Builder gets confused when you try to aggregate expressions that pull from different datasets. Each dataset has its own scope and they don't play nice together.

Honestly, the multi-dataset approach in Report Builder is more trouble than it's worth. If you can restructure to use one dataset, do it. You'll save yourself tons of headaches.

What's your actual data scenario? Maybe there's a simpler way to structure this.


If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.
This response was assisted by AI for translation and formatting purposes.

View solution in original post

2 REPLIES 2
rnola16
Advocate II
Advocate II

Yes, its an indirect approach but this works like charm. In my tablix I got a bunch of cols all coming from different datasets and the Total on these cols doesnt work with a direct Sum func. Yes, autopilot suggested the same approach w alternative. But atleast I dont need to build an other query union. Thank you for the response.

burakkaragoz
Community Champion
Community Champion

Hi @rnola16 ,

 

You can't sum across multiple datasets in Report Builder - it's a known pain point that Microsoft never bothered to fix properly.

Real solutions that actually work:

Fix it at the source: Combine your datasets into one query with UNION or JOIN. Then you can use normal SUM() without the headache.

Custom code hack: Add this to Report Properties → Code:

Dim total As Decimal = 0
Public Function AddUp(val As Decimal) As Decimal
    total = total + val
    Return val
End Function
Public Function GetTotal() As Decimal
    Return total
End Function

In your cells: =Code.AddUp(your IIF mess) In total: =Code.GetTotal()

It's ugly but works.

Why this happens: Report Builder gets confused when you try to aggregate expressions that pull from different datasets. Each dataset has its own scope and they don't play nice together.

Honestly, the multi-dataset approach in Report Builder is more trouble than it's worth. If you can restructure to use one dataset, do it. You'll save yourself tons of headaches.

What's your actual data scenario? Maybe there's a simpler way to structure this.


If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.
This response was assisted by AI for translation and formatting purposes.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors