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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
russell80
Helper III
Helper III

Measure to Filter and Aggregate Across 2 Fact Tables

Looking for some help with this one. I have a simple model where I have a table of projects, called 'Projects', where [Name] is unique, and this is related to the 'Budgets' and 'Invoices' tables with one-to-many relationships. The 'Result' i am trying to get is a table visual for every 'Projects'[Name] with a measure, [Invoiced], which shows a sum of 'Invoices'[Value] for each 'Projects'[Name], for those projects that have a sum of 'Budgets'[Value] greater than 0. Hopefully that makes sense.

 

model.PNG

 

 I got as far as the code below which works for each row in table visual, but the total is off and I can't get this one figured out. I tried adding the ALL filter to CALCULATE to restore it for the Total but that's obviously not working.

Invoiced =
CALCULATE (
    SUM ( 'Invoices'[Value] ),
    FILTER ( 'Budgets', SUM ( 'Budgets'[Values] ) > 0 ),
    ALL ( 'Budgets'[Name] ),
    CROSSFILTER ( 'Budgets'[Name], 'Projects'[Name], BOTH )
)
1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@russell80  can you try this

Measure =
VAR _filterTbl =
    SUMMARIZE (
        FILTER (
            Budgets,
            CALCULATE ( SUM ( Budgets[Value] ), ALLEXCEPT ( Budgets, Budgets[Name] ) ) > 0
        ),
        Budgets[Name]
    )
RETURN
    CALCULATE ( SUM ( Invoices[Value] ), TREATAS ( _filterTbl, Invoices[Name] ) )

 

smpa01_0-1639410434035.png

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

5 REPLIES 5
smpa01
Super User
Super User

@russell80  can you try this

Measure =
VAR _filterTbl =
    SUMMARIZE (
        FILTER (
            Budgets,
            CALCULATE ( SUM ( Budgets[Value] ), ALLEXCEPT ( Budgets, Budgets[Name] ) ) > 0
        ),
        Budgets[Name]
    )
RETURN
    CALCULATE ( SUM ( Invoices[Value] ), TREATAS ( _filterTbl, Invoices[Name] ) )

 

smpa01_0-1639410434035.png

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
russell80
Helper III
Helper III

Thanks @amitchandak . I gave that a go and it works for each row in the result, but the total is not right. I think for the total, you don't have the filter context to be able to sum the budgets for each project, so all the budgets are summed which comes back as a true condition for the "> 0" filter.

@russell80 , These was small mistake, home you have forced row context using values and sumx

 

example or return 

 

sumx(filter(Values(Project[project]), _bud >0),_inv)

 

or

 

sumx(summarize(Project,Project[project],"_1",_inv, "_2" _bud), if[_2]>0 ,[_1], blank() )

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks @amitchandak . I tried both options, see below but I still don't get the correct total
results.PNGrelationship.PNG

amitchandak
Super User
Super User

@russell80 , Try a measure like 

Measure =
var _inv = calculate(sum(Invoices[Value]))
var _bud = calculate(sum(Budget[Value]))
return
sumc(filter(Values(Project[project]), _bud >0),_inv)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.