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, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
MattTrollope
Frequent Visitor

Returning distinct values using a Measure

I need my Date Table to operate on both the Join and Close dates of an entity to capture the number of contacts with a role on a given date. As I can only have one active relationship, I'm using a Measure to capture this data:

 

MattTrollope_0-1728404179090.png

 

This returns 1 for each qualifying row in the 'Role' entity, so I can use this to determine the total number of contacts with roles. Because some contacts have several roles it returns a row for each role, but I need it to show the number of 'distinct' contacts with roles, and can't find a way to achieve this. Any assistance would be greatly appreciated.

1 ACCEPTED SOLUTION

Hi @MattTrollope ,

You can create a measure as below to get the number of distinct contacts, please find the details in the attachment.

Number of distinct Contacts = 
VAR _date =
    SELECTEDVALUE ( 'Date'[Date] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Role'[ContactID] ),
        FILTER ( 'Role', 'Role'[JoinDate] <= _date && 'Role'[CloseDate] >= _date )
    )

vyiruanmsft_1-1728537763179.png

Best Regards

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

View solution in original post

4 REPLIES 4
v-yiruan-msft
Community Support
Community Support

Hi @MattTrollope ,

Do you want to get the number of 'distinct' contacts with roles? Could you please provide some raw data in your tables(exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

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

Contact_Role 

Thank you for your reply.

I have attached link to example pbix file demonstrating the problem. I'm trying to find the number of distinct Contacts with active Roles on a given date (not the number of roles each Contact has on the given date). The example shows the number of roles each contact has on the date. In the screenshot below I want to show 1 DistinctActiveRole for each Contact in the lower table.

MattTrollope_0-1728469168227.png

Thanks for your assistance.

 

Hi @MattTrollope ,

You can create a measure as below to get the number of distinct contacts, please find the details in the attachment.

Number of distinct Contacts = 
VAR _date =
    SELECTEDVALUE ( 'Date'[Date] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Role'[ContactID] ),
        FILTER ( 'Role', 'Role'[JoinDate] <= _date && 'Role'[CloseDate] >= _date )
    )

vyiruanmsft_1-1728537763179.png

Best Regards

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

Thank you very much for your asistance. This now solves my problem, I wondered if a different approach might be the solution, and you have provided it for me, thank you again.

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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

Top Kudoed Authors