Forum Discussion

jgrob3's avatar
jgrob3
Advocate I
7 years ago
Solved

Compounds in beer & snacks problem

I have 4 tables in my model:   flavors: list of flavors & IDs   compounds: list of the component compounds that make up each flavor. Each row in the component table has its individual compound ID...
  • jgrob3's avatar
    jgrob3
    7 years ago

    Thank you Frank for all your help & efforts!

     

    There might be a better way of doing this but I ended up solving my own problem using the following solution:

    • Duplicate the compounds_flavors table to create a snacks compounds_flavors table and a separate beer compounds_flavors table
    • Merge the compound name and description into each table (not really necessary but it made it easier than just having an ID)
    • The tblSnacks is joined to snacks compounds_flavors using the [flavor] field with a many-to-many join and "Both" cross-filtering enabled.  The tblBeer is joined to its corresponding table the same way.
    • My measure to count the number of compounds in common then became quite simple:
    Number of Compounds =
    COUNTROWS (
        DISTINCT (
            INTERSECT (
                VALUES ( 'beer compounds_flavors'[compound_id] ),
                VALUES ( 'snacks compounds_flavors'[compound_id] )
            )
        )
    )

    Because I'm matching on the flavor names (the list of ingredients for each beer & snack didn't have flavor ID), I also created a couple of extra tables to show which flavors matched (merge query > inner join) and which didn't (merge query > left anti join).

     

    The end result: