Forum Discussion

Medo1110's avatar
Medo1110
Regular Visitor
3 years ago
Solved

Filter Table in special way based on column from another table

Hi! Im struggling to create a table which is filtered by value selected from another table: I have 2 Tables: Customers and Coffeeshops.  Customer Coffeeshop ID Reciept A 1  $    ...
  • speedramps's avatar
    2 years ago

    Click here to download solution

    Download PBIX 

     

     

    How it works ...

     

    Create a related and unrelated copy of shop table.
    Use one to pick (slice) and the other to display.
    Otherwise it is complicated to slice a shop and display the other shops ! 

     

    Create a measure

     

    Is Valid Customer = 
    VAR pickshop = SELECTEDVALUE('Shop picklist'[CofeeshopID])    -- getspicked shop id
    VAR customers =                                               -- get list of customers who visted picked shop    
    CALCULATETABLE(
        VALUES(Sales[Customer]),
        ALL(Sales),
        Sales[Coffeeshop ID] = pickshop)
    VAR thisshop = SELECTEDVALUE(Sales[Coffeeshop ID])             -- get shop being output
    VAR thiscustomer= SELECTEDVALUE(Sales[Customer])               -- get customer being output
    RETURN
    SWITCH(TRUE(),                                                 
    thisshop = pickshop, "N",                                       -- ignore picked shop
    thiscustomer in customers, "Y"                                  -- flag customers who are in the list
    )

     

     

    Fiter you reports using the measure

     

    Pay great care to use the correct table and field names.
    iI you use the shop or the customer from the wrong table then the solutoon wont work.
    Download my example and copy the code.

     

    Thanks for the clear description of the problem with example data. I wish everyone did that!

    Remember we are unpaid volunteers and you are receiving expert free help.
    This solution works and does exactly what you asked.
    So please be polite and quickly click the [accept as solution] and thumbs up and the button to leave kudos. 

    One question per ticket please. If you need to change or extend your request then please raise a new ticket.

    You will get a quicker response and each volunteer solver will get the kudos they deserve. Thank you ! 

    If you quote speedramps in your next tickets then I will then receive an automatic notification, and will be delighted to help you again.