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
Anonymous
Not applicable

Dax Improvement/Optimization Question

I have a question where I am looking for another way to write this DAX measure.

 

This involves two tables. Table 1 is Accounts and Table 2 is Contacts. The relationship is one to Many (Accounts to Contacts).

 

I am looking to get a total count of Accounts where all of their Contacts do not have an email.

My dax so far: 

 

CALCULATE(DISTINCTCOUNT(accounts[accountid]),contacts[emailaddress] = BLANK(),CROSSFILTER(contacts[accountid],accounts[accountid],Both),FILTER(dyn_accounts,[Total_Contacts] = [Total_Contacts_Missing_Email]))

 

 

 

The hardest part I think is the last part about where we need to only count accounts that have all of their contacts missing an email. The way I get around that is by creating two measures outside this one comparing an account total contacts to their total contacts missing an email.

 

Any improvement suggestions? 

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

@Anonymous , you may try the following method: 

First add a column to contacts table:

HasEmailAddress =
CALCULATE (
    IF (
        MAXX (
            contacts,
            IF ( ISBLANK ( contacts[emailaddress] ) || contacts[emailaddress] = "", 0, 1 )
        ) = 1,
        1,
        0
    ),
    ALLEXCEPT ( contacts, contacts[accountid] )
)

v-jingzhang_0-1602583622385.png

Then create a measure and put it in a card to display it.

Count of no email = 
CALCULATE (
    DISTINCTCOUNT ( contacts[accountid] ),
    contacts[HasEmailAddress] = 0
)

v-jingzhang_1-1602583831287.png

Best Regards,

Community Support Team _ Jing Zhang

If this post helps, please consider Accept it as the solution to help other members find it.

View solution in original post

2 REPLIES 2
v-jingzhang
Community Support
Community Support

@Anonymous , you may try the following method: 

First add a column to contacts table:

HasEmailAddress =
CALCULATE (
    IF (
        MAXX (
            contacts,
            IF ( ISBLANK ( contacts[emailaddress] ) || contacts[emailaddress] = "", 0, 1 )
        ) = 1,
        1,
        0
    ),
    ALLEXCEPT ( contacts, contacts[accountid] )
)

v-jingzhang_0-1602583622385.png

Then create a measure and put it in a card to display it.

Count of no email = 
CALCULATE (
    DISTINCTCOUNT ( contacts[accountid] ),
    contacts[HasEmailAddress] = 0
)

v-jingzhang_1-1602583831287.png

Best Regards,

Community Support Team _ Jing Zhang

If this post helps, please consider Accept it as the solution to help other members find it.

DataInsights
Super User
Super User

@Anonymous,

 

Try this measure:

 

Accounts without Email = 
VAR vAccount =
    MAX ( Accounts[Account ID] )
VAR vContacts =
    FILTER (
        ALL ( Contacts ),
        Contacts[Account ID] = vAccount
            && NOT ISBLANK ( Contacts[Email] )
    )
VAR vResult =
    IF ( COUNTROWS ( vContacts ) > 0, 0, 1 )
RETURN
    vResult

 

The matrix/table visual should use Account ID from the Accounts table.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.