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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Paulo84
Frequent Visitor

DISTINCTCOUNT with conditions across several tables

Hi All, 

 

Was wondering if you may be able to assit with a scenario that has me stumped.

 

I have 3 x tables in my model:

 

* A 'Key Date' Table with a column of dates

* A 'Transactions' table with a unique Client ID, transaction date and transaction amount 

* A 'Client Details' table linked to the 'Transactions' table through unique Client ID

 

I'm then trying to create a calculated column on the 'Key Date' table which will count the number of clients who meet 2 criteria:

 

* Client has a 'date became client' within 4 months of key date; and

* Client has not made a transaction as of the 'key date'

 

Another scenario I'm trying to determine is a count of clients who have made a transaction within 13 months of each key date. 

 

Any assistance is greatly appreciated!

 

 

1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @Paulo84 ,

 

Check the formula.

Column 3 =
CALCULATE (
    DISTINCTCOUNT ( 'Client Details'[Client ID] ),
    FILTER (
        'Client Details',
        'Client Details'[date became client] >= EDATE ( 'Key date'[date], -3 )
            && 'Client Details'[date became client] <= 'Key date'[date]
    )
)
    - CALCULATE (
        DISTINCTCOUNT ( 'Client Details'[Client ID] ),
        FILTER ( Transactions, Transactions[transaction date] = 'Key date'[date] )
    )

Here's my sample data and result.

1.PNG2.PNG3.PNG

 

Best Regards,

Jay

 

Community Support Team _ Jay Wang

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

 

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

4 REPLIES 4
v-jayw-msft
Community Support
Community Support

Hi @Paulo84 ,

 

Check the formula.

Column 3 =
CALCULATE (
    DISTINCTCOUNT ( 'Client Details'[Client ID] ),
    FILTER (
        'Client Details',
        'Client Details'[date became client] >= EDATE ( 'Key date'[date], -3 )
            && 'Client Details'[date became client] <= 'Key date'[date]
    )
)
    - CALCULATE (
        DISTINCTCOUNT ( 'Client Details'[Client ID] ),
        FILTER ( Transactions, Transactions[transaction date] = 'Key date'[date] )
    )

Here's my sample data and result.

1.PNG2.PNG3.PNG

 

Best Regards,

Jay

 

Community Support Team _ Jay Wang

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

 

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
v-jayw-msft
Community Support
Community Support

Hi @Paulo84 ,

 

I'm not sure what is "date became client" in your model. Is it transaction date or another column in Client Details table?

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

Hi @v-jayw-msft ,

 

'Date became client' is not a transactional date - Think of it as the date they 'signed on' to become a client (this date will be prior to transacting).

 

It is another column in the client details table.

 

 

MFelix
Super User
Super User

Hi @Paulo84 ,

 

Can you please share same sample data and expected result ,please see this post regarding How to Get Your Question Answered Quickly (courtesy of @Greg_Deckler) and How to provide sample data in the Power BI Forum (courtesy of @ImkeF).

 

Based on your data the results can vary, so if you provide a sample data it's easier to get the result you need.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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