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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Sibrulotte
Helper IV
Helper IV

Distinct count from another table on max date

Hi, 

two tables: 

Balances:

DateAccountAmount
2024-05-27110
2024-05-27210
2024-05-27315
2024-05-27420
2024-05-27650
2024-04-3015
2024-04-3025
2024-04-30540
2024-04-30310

 

Acounts:

AccountClient
1A
2B
3C
4A
5D
6E

 

 

A client can have more than one account, pretty basic.

When I try to do a distinct count of clients for the max date (in this case may 27th) I get the 

 

 

nb_eparg_solde_max =
// define the max date
var max_Balances = filter(all(Balances), Balances[Date] = max(Balances[Date]))
 
return
calculate(distinctcount(Accounts[Clients]), max_solde)
 
 
I should be getting 4 clients but I get all 5 of them...
2 ACCEPTED SOLUTIONS
rajendraongole1
Super User
Super User

Hi @Sibrulotte - You need to follow a structured approach to ensure that you're considering only the clients that have transactions on the maximum date without duplication

 

Use the below measure

 

DistinctClientCountOnMaxDate = 

VAR MaxDateValue = [MaxDate]
RETURN
CALCULATE(
    DISTINCTCOUNT(Table2[Client]),
    FILTER(
        Table1,
        Table1[Date] = MaxDateValue
    )
)
 output:
 
rajendraongole1_0-1717002976722.png

 

 

can you please use the above logic and let know.

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





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

Proud to be a Super User!





View solution in original post

ThxAlot
Super User
Super User

ThxAlot_0-1717006851586.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table with a relationship (many to One and Sigle) from the Date column of the Balances table to the Date column of the Calendar Table.  In the Balances tables, write this calculated column formula to bring over the Client from the Accounts table

Client = related(Accounts[Client])

Write this measure

Measure = calculate(distinctcount(Balances[Client]),datesbetween(calendar[date],max(calendar[date]),max(calendar[date])))

Drag this measure to a card visual.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi

 

Please help me with how I prepared for the Microsoft Power BI exam.

ThxAlot
Super User
Super User

ThxAlot_0-1717006851586.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



rajendraongole1
Super User
Super User

Hi @Sibrulotte - You need to follow a structured approach to ensure that you're considering only the clients that have transactions on the maximum date without duplication

 

Use the below measure

 

DistinctClientCountOnMaxDate = 

VAR MaxDateValue = [MaxDate]
RETURN
CALCULATE(
    DISTINCTCOUNT(Table2[Client]),
    FILTER(
        Table1,
        Table1[Date] = MaxDateValue
    )
)
 output:
 
rajendraongole1_0-1717002976722.png

 

 

can you please use the above logic and let know.

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





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

Proud to be a Super User!





Please can  someone help me with what I can buy to practice for the Microsoft  Power BI exam   after two weeks I have an exam 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.