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
ejoneslor
Helper II
Helper II

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

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
Super User
Super User

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


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.

@ejoneslor 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.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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
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.