Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Finding Common attributes between two different Datasets

I have two data sets Group A and Group B as shown below.      GroupA Breakfast Lunch Dinner   GroupB Breakfast Lunch Dinner A1 Cereal Pasta Vegetables   B1 Cereal Pasta Veget...
  • TomMartens's avatar
    5 years ago

    Hey Anonymous ,

     

    I created two tables Table A and Table B

    I creatd 2 measures (looking for A in B), just create additional measures for the other way round.

    These are my measures:

    level of similarity = 
    IF( HASONEVALUE( 'TableA'[GroupA] )
    
        , IF( HASONEVALUE( 'TableB'[GroupB] )
            , var searchstring = 
                CONCATENATEX(
                    'TableA'
                    , COMBINEVALUES( "|", 'TableA'[Breakfast] , 'TableA'[Lunch] , 'TableA'[Dinner] )
                    , "|"
                )
            return
                SUMX(
                    'TableB'
                    , var stringToCompare = COMBINEVALUES( "|", 'TableB'[Breakfast] , 'TableB'[Lunch] , 'TableB'[Dinner] )
                    var lengthSearch = PATHLENGTH( searchstring )
                    var t =
                        ADDCOLUMNS( 
                            GENERATESERIES( 1 , lengthSearch , 1 )
                            , "isfound" , IF( PATHCONTAINS( stringToCompare , PATHITEM( searchstring , [Value] ) ) , 1 , 0 )
                        )
                    return
                    SUMX( t , [isfound] )
                )
            , BLANK()
        )
    , "Select one item from Group A"
    )

    and

    similar items = 
    IF( HASONEVALUE( 'TableA'[GroupA] )
        , IF( HASONEVALUE( 'TableB'[GroupB] )
            , var searchstring = 
                CONCATENATEX(
                    'TableA'
                    , COMBINEVALUES( "|", 'TableA'[Breakfast] , 'TableA'[Lunch] , 'TableA'[Dinner] )
                    , "|"
                )
            return
                CONCATENATEX(
                    'TableB'
                    , var stringToCompare = COMBINEVALUES( "|", 'TableB'[Breakfast] , 'TableB'[Lunch] , 'TableB'[Dinner] )
                    var lengthSearch = PATHLENGTH( searchstring )
                    var t =
                        ADDCOLUMNS( 
                            GENERATESERIES( 1 , lengthSearch , 1 )
                            , "founditem" , IF( PATHCONTAINS( stringToCompare , PATHITEM( searchstring , [Value] ) ) , PATHITEM( searchstring , [Value] ) , BLANK() )
                        )
                    return
                    CONCATENATEX( t , [founditem] , ", " )
                )
            , BLANK()
        )
    , "Select one item from Group A"
    )

    This allows to create this report:

    Hopefully, this provides some ideas on how to tackle your challenge.

     

    Regards,

    Tom