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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
azaterol
Helper V
Helper V

Aggregate distinct customers

Hello everyone,

 

I have a matrix. I have two tables. A customer table and an invoice table.

 

These are each connected bidirectionally with the customer number.

I have the formula: purchasing POS = COUNTROWS('Customer table')

in a matrix the number of daily purchasing customers.


I have year-month-day as a line. The column is the measure purchasing POS.

Now I want the measure to aggregate. In addition to aggregating, the measure should not count up again what customers purchased on a previous day in the current month. In other words, if a customer has already ordered on a previous day in the current month, this customer should not be counted again.

 

 

azaterol_1-1725572015111.png

 

azaterol_3-1725573449689.png

 

SAMPLE Data: https://easyupload.io/wr38ek

 

I hope you can help me. 

 

 

7 REPLIES 7
suparnababu8
Solution Sage
Solution Sage

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

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

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

Don't judge other people without knowing what they do for you. 
Thanks!

 

 

 

 

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

azaterol_0-1725814296035.png

 

 

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.

lbendlin
Super User
Super User

These are each connected bidirectionally with the customer number.

Why bidirectional?

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

hello @lbendlin ,

 

here is a sample: https://easyupload.io/wr38ek

 

What is wrong with bidirectional?

Here's a different view of your data model. That Documentation table looks weird. What's the story behind it?

 

lbendlin_0-1725828675615.png

 

What is the first buy column intended to achieve? There is also a data quality issue for Documentation Nr. 4996 - conflicting customer IDs.

 

 

 

Bidirectional = bad.  This here is Power BI, not Qlik.  Power BI wants Star schemas.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.