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.
Hello folks,
I have a calculation for the repeating customers per venue (restaurant) that goes like this:
Solved! Go to Solution.
Hi, @Anonymous
Please try the following measure. The pbix file is attached in the end.
Result =
var _restaurant = SELECTEDVALUE('Table'[Restaurant])
var tab =
SUMMARIZE(
FILTER(
ALL('Table'),
NOT('Table'[Restaurant] in DISTINCT(Restaurant[Restaurant]))
),
'Table'[AccountID],
"Flag",
IF(
COUNTROWS(
FILTER(
ALL('Table'),
[AccountID]=EARLIER('Table'[AccountID])&&
[Restaurant] in DISTINCT(Restaurant[Restaurant])
)
)>0,
1,0
)
)
var newtab =
CALCULATETABLE(
DISTINCT('Table'[AccountID]),
FILTER(
tab,
[Flag]=1
)
)
return
IF(
NOT(SELECTEDVALUE('Table'[Restaurant]) in DISTINCT(Restaurant[Restaurant])),
COUNTROWS(
FILTER(
ALL('Table'),
[AccountID] in newtab&&
[Restaurant]=SELECTEDVALUE('Table'[Restaurant])
)
)
)
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @Anonymous
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may create a measure as below.
Repeat Customers =
var t =
SUMMARIZE(
ALLSELECTED('Table'),
'Table'[AccountID],
'Table'[Restaurant],
"Count",
COUNTROWS('Table')
)
var tab =
SUMMARIZE(
'Table',
'Table'[AccountID],
"Flag",
var _count =
COUNTROWS(
FILTER(
t,
[AccountID]=EARLIER('Table'[AccountID])&&
[Count]>=2
)
)
return
IF(
_count>0,
1,0
)
)
var _result =
COUNTROWS(
FILTER(
tab,
[Flag]=1
)
)
return
IF(
ISBLANK(_result),
0,
_result
)
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Allan,
You have a great solution that I can use in my other visual if I want to see the actual accounts.
But my goal is to show all the other venues the repeating customer visited.
Like in the data example you created, if you select venue A, that Accounts 1, 2, 3 and 4 visited, the venues B, C, F, D, E should show with counts.
Thank you,
Stan
Just to be more clear on the final result. I should have a Venue slicer with all restaurants. If I pick Venue A, I should be able to see the following:
Venue | Count |
B | 2 |
C | 3 |
D | 2 |
F | 1 |
Hi, @Anonymous
I'm sorry for the late reply. You may try to create a calculated table and a measure as below. The pbix file is attached in the end.
Calculated table:
Restaurant = DISTINCT('Table'[Restaurant])
Measure:
Result =
var _restaurant = SELECTEDVALUE('Table'[Restaurant])
var tab =
SUMMARIZE(
ALL('Table'),
'Table'[AccountID],
"Count",
IF(
COUNTROWS(
FILTER(
ALL('Table'),
[AccountID]=EARLIER('Table'[AccountID])&&
[Restaurant]=_restaurant
)
)>0,
1,0
)
)
return
IF(
NOT(SELECTEDVALUE('Table'[Restaurant]) in DISTINCT(Restaurant[Restaurant])),
SUMX(
tab,
[Count]
)
)
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Allan, thank you for your reply! I checked the pbix and played with the selections. Seems like it works for some seletions and doesn't work for others. For instance, baced on the data if I select restaurant F (only AccountID = 3 visited that venue), I am expected to see A - 1, B - 0, D -1 but I see the following:
I will try to think on your code but if you have any idea please post it.
Thank you,
Stan
Hi, @Anonymous
Please try the following measure. The pbix file is attached in the end.
Result =
var _restaurant = SELECTEDVALUE('Table'[Restaurant])
var tab =
SUMMARIZE(
FILTER(
ALL('Table'),
NOT('Table'[Restaurant] in DISTINCT(Restaurant[Restaurant]))
),
'Table'[AccountID],
"Flag",
IF(
COUNTROWS(
FILTER(
ALL('Table'),
[AccountID]=EARLIER('Table'[AccountID])&&
[Restaurant] in DISTINCT(Restaurant[Restaurant])
)
)>0,
1,0
)
)
var newtab =
CALCULATETABLE(
DISTINCT('Table'[AccountID]),
FILTER(
tab,
[Flag]=1
)
)
return
IF(
NOT(SELECTEDVALUE('Table'[Restaurant]) in DISTINCT(Restaurant[Restaurant])),
COUNTROWS(
FILTER(
ALL('Table'),
[AccountID] in newtab&&
[Restaurant]=SELECTEDVALUE('Table'[Restaurant])
)
)
)
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Allan, that did the trick! Thank you so much!!!
@Anonymous - It's difficult to say other than you will have to capture your current values for the customer and restaurant and then change your filter context to pick up the other restaurants. Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882
Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
111 | |
100 | |
80 | |
64 | |
58 |
User | Count |
---|---|
148 | |
111 | |
93 | |
84 | |
66 |