Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I have two tables CustInvoiceJour , CustInvoiceTrans are connected by the InvoiceId field in both tables.
I added a slicer for InvoiceDate from the CustInvoiceTrans table or CustInvoiceJour both of them are Same.
What if I want to find customers who do not have any sales from period date , meaning if I selected from 1/1/2024 to 30/3/2024, want to see customers who do not have any sales in this range date.
How do I write DAX that does this for me ?
Solved! Go to Solution.
Hi @amal_01 ,
Thank you for your feedback. I’ve decided to take a different approach by visualizing customers with no sales, using a flag to mark them with a value of 1.
NoSalesFlag =
VAR SalesInRange =
CALCULATE(
COUNTROWS(CustInvoiceJour), -- Count rows in the table
CustInvoiceJour[LineAmount] > 0, -- Include rows with sales
CustInvoiceJour[InvoiceDate] >= MIN(CustInvoiceJour[InvoiceDate]), -- Date range start
CustInvoiceJour[InvoiceDate] <= MAX(CustInvoiceJour[InvoiceDate]) -- Date range end
)
RETURN
IF(SalesInRange = 0, 1, 0) -- Return 1 for no sales, otherwise 0
Instead of using the entire customer master table to identify customers with no sales, I’ve used only the sales transaction table, CustInvoiceJour. This approach ensures that only customers relevant to the selected periods are considered for assessing no sales, as the customer master data may include old customers with no transactions in recent years.
The resulting output looks like below:
I've attached an example pbix file for your reference.
Best regards,
Hi @amal_01 ,
To find customers who do not have any sales within a specified date range, you can create a DAX measure that identifies customers with no transactions during the selected period and filters them in your visualization. Here’s how to achieve this:
Create a measure to identify customers with no sales in the selected range:
NoSalesCustomers =
VAR AllCustomers = VALUES(CustInvoiceJour[InvoiceAccount])
VAR SalesCustomers =
CALCULATETABLE(
VALUES(CustInvoiceJour[InvoiceAccount]),
CustInvoiceTrans[LineAmount] > 0,
CustInvoiceTrans[InvoiceDate] >= MIN(CustInvoiceTrans[InvoiceDate]),
CustInvoiceTrans[InvoiceDate] <= MAX(CustInvoiceTrans[InvoiceDate])
)
RETURN
EXCEPT(AllCustomers, SalesCustomers)
This measure uses the EXCEPT function to find customers in AllCustomers that are not in SalesCustomers.
Use the NoSalesCustomers measure in a table or matrix visual to display the corresponding InvoiceAccount and DeliveryName.
NoSalesCustomersTable =
ADDCOLUMNS(
EXCEPT(
VALUES(CustInvoiceJour[InvoiceAccount]),
CALCULATETABLE(
VALUES(CustInvoiceJour[InvoiceAccount]),
CustInvoiceTrans[LineAmount] > 0,
CustInvoiceTrans[InvoiceDate] >= MIN(CustInvoiceTrans[InvoiceDate]),
CustInvoiceTrans[InvoiceDate] <= MAX(CustInvoiceTrans[InvoiceDate])
)
),
"Customer Name", RELATED(CustInvoiceJour[DeliveryName])
)
This creates a standalone table listing all customers without sales, including their names.
Key Notes:
Best regards,
@DataNinja777
thanks for your effort.
but this measure gave me the customers have sales in selected period
Hi @amal_01 ,
Thank you for your feedback. I’ve decided to take a different approach by visualizing customers with no sales, using a flag to mark them with a value of 1.
NoSalesFlag =
VAR SalesInRange =
CALCULATE(
COUNTROWS(CustInvoiceJour), -- Count rows in the table
CustInvoiceJour[LineAmount] > 0, -- Include rows with sales
CustInvoiceJour[InvoiceDate] >= MIN(CustInvoiceJour[InvoiceDate]), -- Date range start
CustInvoiceJour[InvoiceDate] <= MAX(CustInvoiceJour[InvoiceDate]) -- Date range end
)
RETURN
IF(SalesInRange = 0, 1, 0) -- Return 1 for no sales, otherwise 0
Instead of using the entire customer master table to identify customers with no sales, I’ve used only the sales transaction table, CustInvoiceJour. This approach ensures that only customers relevant to the selected periods are considered for assessing no sales, as the customer master data may include old customers with no transactions in recent years.
The resulting output looks like below:
I've attached an example pbix file for your reference.
Best regards,
User | Count |
---|---|
15 | |
13 | |
12 | |
10 | |
10 |
User | Count |
---|---|
19 | |
15 | |
14 | |
11 | |
10 |