Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello Power BI community!
I have what looks to be a simple task. I have a table with restaurant reservations. I need to find the repeating customers. In other words I need to do counts of customers where count > 1. This is what I wrote:
If I do the same calculation in SQL Server I get:
T-SQL
SELECT DISTINCT COUNT(ContactName), Venue
FROM
(
SELECT COUNT(Contact_Name__c) CNT, Contact_Name__c AS ContactName, Venue_Name__c AS Venue
FROM [AnalyticsBI].[sf].[Resy]
GROUP BY Contact_Name__c, Venue_Name__c
HAVING COUNT(Contact_Name__c) > 1
) sql1
GROUP BY Venue
Does anybody have any idea why the counts are off?
Thanks!
Stan
Solved! Go to Solution.
Hi @Anonymous,
Might be able to help on this one. The reason your numbers are too high is likely because your haven't initiated context transition in your FILTER statement. FILTER iterates row-by-row and will be putting the value of the DISTINCTCOUNT of customers in every row (this is always going to be > 1 unless you have 1 or zero customers). Try this
Distinct Customers =
COUNTROWS(
FILTER(
VALUES( Resy[Contact_Name__c] ),
CALCULATE( COUNTROWS( Resy ) ) > 1
)
)
Effectively this formula create a table with the unique list of Contact_Name_c (the VALUES) and iterates over this keeping the Contact_Name_c where there is more than 1 row in the table. The COUNTROWS then counts these up.
Hope it helps.
Kris
Hi @Anonymous,
Might be able to help on this one. The reason your numbers are too high is likely because your haven't initiated context transition in your FILTER statement. FILTER iterates row-by-row and will be putting the value of the DISTINCTCOUNT of customers in every row (this is always going to be > 1 unless you have 1 or zero customers). Try this
Distinct Customers =
COUNTROWS(
FILTER(
VALUES( Resy[Contact_Name__c] ),
CALCULATE( COUNTROWS( Resy ) ) > 1
)
)
Effectively this formula create a table with the unique list of Contact_Name_c (the VALUES) and iterates over this keeping the Contact_Name_c where there is more than 1 row in the table. The COUNTROWS then counts these up.
Hope it helps.
Kris
Kris, that did the trick! Thank you! I will still have to grasp the DAX.
User | Count |
---|---|
75 | |
74 | |
44 | |
31 | |
27 |
User | Count |
---|---|
99 | |
89 | |
52 | |
48 | |
46 |