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
Anonymous
Not applicable

Select venues with repeating customers based on another venue selection - DAX needed!

Hello folks,

 

I have a calculation for the repeating customers per venue (restaurant) that goes like this:

 

Repeat Customers =
COUNTROWS(
FILTER(
VALUES( Resy[AccountID] ),
CALCULATE( COUNTROWS( Resy ) ) > 1
)
)
 
Now I need to have a table that would show the repeating customer counts per venue when you select another venue in a table or in a slicer. So if you have a guest that visited A restaurant twice or more and that customer visited venue B and G I want to show that. Really stumbled upon that.
 
Thanks,
Stan
1 ACCEPTED 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:

a1.png

 

Best Regards

Allan

 

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

8 REPLIES 8
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

e1.png

 

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:

e2.png

 

e3.png

 

Best Regards

Allan

 

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

Anonymous
Not applicable

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. 

e1.png

 

 

 

 

 

 

 

 

 

 

 

 

 

Thank you,

Stan

Anonymous
Not applicable

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:

 

VenueCount
B2
C3
D2
F1

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:

f1.png

 

Best Regards

Allan

 

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

Anonymous
Not applicable

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:

 

 

zaichusha_1-1599061013870.png

 

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:

a1.png

 

Best Regards

Allan

 

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

 

Anonymous
Not applicable

Allan, that did the trick! Thank you so much!!!

Greg_Deckler
Super User
Super User

@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.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.