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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
FrederikB
Frequent Visitor

Count unique values in other table

I have a table called bookings, and a table called persons. I want to calculate how many different persons have gotten a booking within some time interval.

Bookings:

idDatepersonId
101-03-20221
202-03-20221
303-03-20222
404-03-20223

 

Persons:

id
1
2
3
4

 

I want to know how many bookings each person has had, which I calculate by:

 

total bookings = DISTINCTCOUNT('booking'[id])

 

I can display this in the persons table, and see that it works right.

 

And I then calculate how many unique persons have gotten a booking by:

 

Persons with bookings = 
CALCULATE(
    COUNTROWS('persons)'), 
    FILTER('persons', 'persons'[total bookings] > 0)
)

 

 

When I set a slicer to march 2022, I expect to see:

  • total bookings: 4
    • personID=1, total bookings: 2
    • personID=2, total bookings: 1
    • personID=3, total bookings: 1
  • Persons with bookings: 3
    • PersonID=1,2,3

 

But on 'total bookings' is calculated proberly. And I can't seem take get 'Persons with bookings' right. At the moment it simply returns (Blank) for each of the persons rows.

2 ACCEPTED SOLUTIONS
serpiva64
Solution Sage
Solution Sage

Hi,

you have confused the two Table.

serpiva64_0-1646323052788.png

 

If this post is useful to help you to solve your issue consider giving the post a thumbs up 

 and accepting it as a solution !

 

 

View solution in original post

Hi @FrederikB ,

You can create measures like this to get the result:

total bookings = DISTINCTCOUNT('bookings'[id])
Persons with bookings = 
VAR tab =
    SUMMARIZE (
        'bookings',
        'bookings'[personId],
        "total bookings", [total bookings]
    )
RETURN
    COUNTX ( tab, [personId] )

vyingjl_0-1646706841555.png

 

Best Regards,
Community Support Team _ Yingjie Li
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

3 REPLIES 3
FrederikB
Frequent Visitor

Thank you for your reply, but I am not sure that I either understand what you mean, or that the provdided solution solves the problem.

It seems like 'Persons with bookings' is summed to four, even though only 3 unique persons have gotten a booking.

Hi @FrederikB ,

You can create measures like this to get the result:

total bookings = DISTINCTCOUNT('bookings'[id])
Persons with bookings = 
VAR tab =
    SUMMARIZE (
        'bookings',
        'bookings'[personId],
        "total bookings", [total bookings]
    )
RETURN
    COUNTX ( tab, [personId] )

vyingjl_0-1646706841555.png

 

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

serpiva64
Solution Sage
Solution Sage

Hi,

you have confused the two Table.

serpiva64_0-1646323052788.png

 

If this post is useful to help you to solve your issue consider giving the post a thumbs up 

 and accepting it as a solution !

 

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.