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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Martin_R
Frequent Visitor

How does this DAX Code work for non buying customers

Hi,

I'm currently learning DAX using book the definitive guide to DAX. In the book there is a measure NonBuyingCustomers that doesn't make sense to me. Could someone explain how the variable CustomersWithoutSales is working ?

 

My understanding is that this variable should return a list of CustomerKey where there is no keyvalue in related table Sales. How can this then use the list of customers with sales from sales table to check ISEMPTY ( RELATEDTABLE ( Sales ) ) ?

Coming from a SQL background I would write a query that LEFT JOINS Customers to Sales and returns those Customers without rows in Sales Table for a given ProductName


NonBuyingCustomers =
VAR SelectedCustomers =
    CALCULATETABLE (
        DISTINCT ( Sales[CustomerKey] ),
        ALLSELECTED ()
    )
VAR CustomersWithoutSales =
    FILTER (
        SelectedCustomers,
        ISEMPTY ( RELATEDTABLE ( Sales ) )
    )
VAR Result =
    COUNTROWS ( CustomersWithoutSales )
RETURN
    Result





Martin_R_0-1704869163320.png

https://drive.google.com/file/d/1ZiIgqO4aHb87mh5wrJRjDpzZzSnZQCAn/view?usp=drive_link 

 

 

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@Martin_R,

 

There's an error in the DAX. The variable SelectedCustomers should use Customer[CustomerKey]. It was noted in the errata (at one point all the errors were available but I'm unable to locate that list now). The link below is mentioned on page xix of the book.

 

https://www.microsoftpressstore.com/store/definitive-guide-to-dax-business-intelligence-with-9781509... 

 

The logic is as follows:

 

1. Get a distinct list of all CustomerKey in the Customer dimension table, using the filter context outside the visual (i.e. filters and slicers).

 

2. Filter the list in step 1 to include only CustomerKey not in the Sales fact table.

 

3. Count the rows in step 2.





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

Proud to be a Super User!




View solution in original post

2 REPLIES 2
DataInsights
Super User
Super User

@Martin_R,

 

There's an error in the DAX. The variable SelectedCustomers should use Customer[CustomerKey]. It was noted in the errata (at one point all the errors were available but I'm unable to locate that list now). The link below is mentioned on page xix of the book.

 

https://www.microsoftpressstore.com/store/definitive-guide-to-dax-business-intelligence-with-9781509... 

 

The logic is as follows:

 

1. Get a distinct list of all CustomerKey in the Customer dimension table, using the filter context outside the visual (i.e. filters and slicers).

 

2. Filter the list in step 1 to include only CustomerKey not in the Sales fact table.

 

3. Count the rows in step 2.





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

Proud to be a Super User!




Thank you Data Insights. I found the errata page here.

https://www.sqlbi.com/books/the-definitive-guide-to-dax-2nd-edition/companion/ 

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 Solution Authors