Forum Discussion

samdthompson's avatar
samdthompson
Memorable Member
8 years ago
Solved

DAX to split and transpose

Hello,   I have a model with a significant amount of text in the fact table and a second table of key words. I have created a column using CONCATENATEX to return all instances of matching terms wit...
  • OwenAuger's avatar
    8 years ago

    Hi samdthompson

     

    If you need to do this in DAX, I would suggest that rather than concatenating in the first place, you use GENERATE to create a two-column table containing the Text values (repeated) and all matching Keywords.

     

    Here's an example. I'm guessing a bit with your exact table structure but hopefully this can be adapted.

    Uploaded here to dropbox

     

     Text table

    Text
    ZZZ London aaa New York ZZZ Moscow ZZZ Cairo ZZZ
    ZZZ Nadi ZZZ
    ZZZ Cairo ZZZ Montreal ZZZ
    ZZZ Sydney ZZZ Moscow ZZZ

     

    Keyword table

    Keyword LookupKeyword Full
    LondonLondon, UK
    New YorkNew York, USA
    MoscowMoscow, Russia
    CairoCairo, Egypt
    NadiNadi, Fiji
    MontrealMontreal, Canada
    SydneySydney, Australia

     

    DAX to create calculated table Text and Keyword table

     

    Text and Keyword = 
    GENERATE (
        'Text',
        VAR MatchingKeywords =
            FILTER (
                Keyword,
                NOT ISERROR ( SEARCH ( Keyword[Keyword Lookup], 'Text'[Text] ) )
            )
        RETURN
            SELECTCOLUMNS ( MatchingKeywords, "Keyword", Keyword[Keyword Full] )
    )

     

    Resulting Text and Keyword table

    TextKeyword
    ZZZ London aaa New York ZZZ Moscow ZZZ Cairo ZZZLondon, UK
    ZZZ London aaa New York ZZZ Moscow ZZZ Cairo ZZZNew York, USA
    ZZZ London aaa New York ZZZ Moscow ZZZ Cairo ZZZMoscow, Russia
    ZZZ Sydney ZZZ Moscow ZZZMoscow, Russia
    ZZZ London aaa New York ZZZ Moscow ZZZ Cairo ZZZCairo, Egypt
    ZZZ Cairo ZZZ Montreal ZZZCairo, Egypt
    ZZZ Nadi ZZZNadi, Fiji
    ZZZ Cairo ZZZ Montreal ZZZMontreal, Canada
    ZZZ Sydney ZZZ Moscow ZZZSydney, Australia

     

    You can then slice on Text and put the Keyword on a map visual:

     

     

    Regards,

    Owen