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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

SUMX with filters from different tables

I am trying to calculate and average value for some sales data which works in conjunction with my slicers.

I have some DAX code below which works really well when returning for all of our quoted work.
I need to add an extra filter in to do the same calulation but only when the quote has been accepted. I've tried a number of ways but the values returned are not correct.

The acceptance sits in another table which is connected to my already filtered data via another table. The structure is...

Opportunities, One to Many with Quotes

Quotes, One to Many with Quote Line Items

 

The filter I need to add is 

'Opportunities', Opportunities[StageName] = "Closed Won"

The working DAX I have is 

AveWeeklyRateWon =
SUMX (
    DISTINCT ( 'Date'[Date]),
    CALCULATE (
        SUMX(
            FILTER (
               'Quote Line Items',
                'Quote Line Items'[CreatedDateOnly] = MAX ('Date'[Date])
                    &&'Quote Line Items'[Header_Product__c] = TRUE
                    &&'Quote Line Items'[Selling_Type__c] = "Hire"
            ),
            'Quote Line Items'[Sales_Price__c]
        )
    )
)
/
SUMX (
    DISTINCT ( 'Date'[Date]),
    CALCULATE (
        SUMX(
            FILTER (
               'Quote Line Items',
                'Quote Line Items'[CreatedDateOnly] = MAX ('Date'[Date])
                    &&'Quote Line Items'[Header_Product__c] = TRUE
                    &&'Quote Line Items'[Selling_Type__c] = "Hire"
            ),
            'Quote Line Items'[SBQQ__Quantity__c]
        )
    )
)
 
Any and all help is greatly appreciated.
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thank you @Greg_Deckler for your help. I managed to find a solution without using tables in the end. As shown below.
Your help and input was appreciated.

AveWeeklyRateWon =
SUMX (
    DISTINCT ( 'Date'[Date]),
        CALCULATE (
        calculate(SUM('Quote Line Items'[Sales_Price__c])
                                ,'Quote Line Items'[CreatedDateOnly] = MAX ('Date'[Date])
                                ,'Quote Line Items'[Header_Product__c] = TRUE
                                ,'Quotes'[SBQQ__Primary__c] = TRUE
                                ,'Opportunities'[Contract_Type__c] = "HIRE"
                                ,'Opportunities'[StageName] = "Closed Won"
        )
        )
)
/
SUMX (
    DISTINCT ( 'Date'[Date]),
    CALCULATE (
        calculate(SUM('Quote Line Items'[SBQQ__Quantity__c])
                                ,'Quote Line Items'[CreatedDateOnly] = MAX ('Date'[Date])
                                ,'Quote Line Items'[Header_Product__c] = TRUE
                                ,'Quotes'[SBQQ__Primary__c] = TRUE
                                ,'Opportunities'[Contract_Type__c] = "HIRE"
                                ,'Opportunities'[StageName] = "Closed Won"
        )
    )
)

View solution in original post

4 REPLIES 4
Greg_Deckler
Community Champion
Community Champion

@Anonymous You can often use CALCULATETABLE to get the table you want with the filters you want. Hard to be specific without sample data.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thank you @Greg_Deckler. In my miited previous experience, using a table won;t give me what I need. Tables calculate on load wihich means they don't interact with the slicers or the date ranges as I'd liek them too.
Is it possible to include filters from two different tables in the sam CALCULATE function.
Apologies if my description isn;t great. I'm very new to this.

@Anonymous You can use CALCULATETABLE in a measure. Basically you can potentially use it to filter the table parameter of your SUMX function for example. Works just like CALCULATE but returns a table.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thank you @Greg_Deckler for your help. I managed to find a solution without using tables in the end. As shown below.
Your help and input was appreciated.

AveWeeklyRateWon =
SUMX (
    DISTINCT ( 'Date'[Date]),
        CALCULATE (
        calculate(SUM('Quote Line Items'[Sales_Price__c])
                                ,'Quote Line Items'[CreatedDateOnly] = MAX ('Date'[Date])
                                ,'Quote Line Items'[Header_Product__c] = TRUE
                                ,'Quotes'[SBQQ__Primary__c] = TRUE
                                ,'Opportunities'[Contract_Type__c] = "HIRE"
                                ,'Opportunities'[StageName] = "Closed Won"
        )
        )
)
/
SUMX (
    DISTINCT ( 'Date'[Date]),
    CALCULATE (
        calculate(SUM('Quote Line Items'[SBQQ__Quantity__c])
                                ,'Quote Line Items'[CreatedDateOnly] = MAX ('Date'[Date])
                                ,'Quote Line Items'[Header_Product__c] = TRUE
                                ,'Quotes'[SBQQ__Primary__c] = TRUE
                                ,'Opportunities'[Contract_Type__c] = "HIRE"
                                ,'Opportunities'[StageName] = "Closed Won"
        )
    )
)

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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 Kudoed Authors