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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
trevorloflin
New Member

Calculating aggregates in DirectQuery mode

I'm new to PowerBI and am trying to do something that seems very simple but can't figure it out.

 

I'm working with two SQL Server tables in DirectQuery mode. I'm trying to create a table visualization based on one of the tables that uses an aggregate from the second table, but the aggregate needs to be added to a value from the first table. Here's a simplified example:

 

SQL Tables

Foo
===
ID | Name | FooValue
---------------------
1  | Joe  | 19
2  | Bob  | 23
Bar
===
ID | FooID | BarValue
----------------------
1  | 1     | 5
2  | 1     | 7
3  | 2     | 1

 

Visualization Table (expected)

Name | TotalValue
-------------------
Joe  | 31
Bob  | 24

Where there is a one-to-many relationship between Foo and Bar and "TotalValue" is calculated for each row as the "FooValue" for that row plus the sum of the related "BarValue"s.

 

When I try to create a calculated column ("TotalValue = Foo[FooValue] + SUM(Bar[BarValue]") it won't let me, saying, "Function 'SUM' is not allowed as part of calculated column DAX expressions on DirectQuery models". I understand that there are limitations on DirectQuery models for performance reasons, but surely this is a very simple, performant query and there must be a way to do it. I could easily write a SQL query to do it:

SELECT Foo.Name, Foo.FooValue + SUM(Bar.BarValue) AS TotalValue
FROM Foo
INNER JOIN Bar on Bar.FooID = Foo.ID
GROUP BY Foo.Name, Foo.FooValue

So how do I do it in PowerBI?

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @trevorloflin 

Create relationship as below

15.png

Create a measure

Measure = SUM(foo[foovalue])+SUM(bar[barvalue])

14.png

Best Regards
Maggie

 

Community Support Team _ Maggie Li
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

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @trevorloflin 

Create relationship as below

15.png

Create a measure

Measure = SUM(foo[foovalue])+SUM(bar[barvalue])

14.png

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks! I was missing that a measure takes the context of the row it's in.

Helpful resources

Announcements
Fabric Data Days is here Carousel

Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.