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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jackj
Helper I
Helper I

Calculating a count across disconnected tables

Hi,

 

I am struggling to do what I think should be a very simple calculation.  I have two disconnected tables, Orders and Visits.  Each of them shares a similar UserID column.  It's called 'CustomerID' in Orders and 'UserID' in visits.  Most values are the same, however not all IDs appear in both columns and I am unable to create a relationship between the two tables.

 

All that I am looking to do is create a calculated measure in the "Visits" column which counts the number of times each 'UserID' in visits appears in the 'CustomerID' column in Orders.  This seems to be a very simple ask, but I am struggling to make this work in PowerBI.  Does anyone have any suggestions?

 

Thanks in advance.

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@jackj usually in scenarios like this you should have a common dimension table with a unique user id and link these two together, anyhow try the following expression to get the count:

 

Count = 
CALCULATE (
COUNTROWS ( Customer ),
TREATAS ( VALUES ( Visits[UserId] ), Customer[CustomerId] )
)

 

Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

5 REPLIES 5
parry2k
Super User
Super User

@jackj same thing, just use different calculation

 

Count = 
CALCULATE (
SUM ( Customers[Sales] ),
TREATAS ( VALUES ( Visits[UserId] ), Customer[CustomerId] )
)


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@jackj sorry not sure what is your question?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

In addition to counting, I want to be able to sum the sales value in "Orders" that corresponds to the selected user ID.  Hope that clarifies.

parry2k
Super User
Super User

@jackj usually in scenarios like this you should have a common dimension table with a unique user id and link these two together, anyhow try the following expression to get the count:

 

Count = 
CALCULATE (
COUNTROWS ( Customer ),
TREATAS ( VALUES ( Visits[UserId] ), Customer[CustomerId] )
)

 

Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thank you!  This worked for the count.  One other question - how could I do something similar to be able to do a sumif-like function rather than a count with this same data, i.e., taking the sum of sales in the "orders" table based on the userID from the "visits" table?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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