Forum Discussion
Aggregate distinct customers
Hi azaterol
To achieve this in Power BI, you need to create a measure that counts distinct customers who made a purchase on any given day within the current month, but ensures that customers who have already made a purchase earlier in the month are not counted again. Here’s how you can do it:
Step-by-Step Instructions
Create a Calendar Table:
- Ensure you have a calendar table in your model.
Calendar = CALENDAR(MIN('InvoiceTable'[Date]), MAX('InvoiceTable'[Date]))
Create a Relationship:
- Create a relationship between your Calendar table and the InvoiceTable using the date column.
Create a Measure to Count Distinct Customers
DistinctCustomers =
CALCULATE(
DISTINCTCOUNT('InvoiceTable'[CustomerNumber]),
FILTER(
'InvoiceTable',
'InvoiceTable'[Date] <= MAX('Calendar'[Date]) &&
'InvoiceTable'[Date] >= STARTOFMONTH('Calendar'[Date])
)
)
- Create a Measure to Exclude Previously Counted Customers
UniquePurchasingCustomers =
CALCULATE(
DISTINCTCOUNT('InvoiceTable'[CustomerNumber]),
FILTER(
'InvoiceTable',
'InvoiceTable'[Date] = MAX('Calendar'[Date]) &&
NOT 'InvoiceTable'[CustomerNumber] IN
CALCULATETABLE(
VALUES('InvoiceTable'[CustomerNumber]),
FILTER(
'InvoiceTable',
'InvoiceTable'[Date] < MAX('Calendar'[Date]) &&
'InvoiceTable'[Date] >= STARTOFMONTH('Calendar'[Date])
)
)
)
)
Add the Measure to Your Matrix:
- Use the UniquePurchasingCustomers measure in your matrix visual.
Example Visualization
- Rows: Year-Month-Day
- Values: UniquePurchasingCustomers
This setup ensures that each customer is only counted once per month, regardless of how many times they make a purchase within that month.
suparnababu8
Can you please stop using ChatGPT?
I went to the trouble of uploading an example so that I wouldn't receive an incorrect bot-generated answer.
Can someone give me a correct solution like the good old days without AI? I am very grateful for that. Thanks to everyone who helps.
- suparnababu81 year agoSuper User
Hello azaterol
I'm not using chatGPT.
I am trying to solve your problem. Based on your input I given soultion for that. I think you misundertanded me.
What you are expecting as a output I'm not clear, But as per my understanding, now I tried one solution for you and attaching here pbix file. sample_demo.pbixDon't judge other people without knowing what they do for you.
Thanks!- azaterol1 year agoHelper V
suparnababu8Please stop commenting on my post. I say this with all politeness. Since I use ChatGPT from time to time myself, I know the type of solutions ChatGPT suggests. Here is another post from you that corresponds exactly to the ChatGPT pattern.
Again, your ChatGPT solution is absolutely useless. Please stop. Everyone notices it.
I hope that someone seriously thinks about my problem. I would like to thank everyone for their effort.