Forum Discussion

WinterMist's avatar
WinterMist
Icon for Impactful Individual rankImpactful Individual
2 years ago
Solved

Unable to Reference VAR Table Columns

Hello Community -    So I am aware that: "a variable name cannot be used as a table name in a column reference" (https://www.sqlbi.com/articles/table-and-column-references-using-dax-variables/) ...
  • AlexisOlson's avatar
    2 years ago

    One option is to use v1 as a filter table like this:

    VAR v1 =
        FILTER (
            ALL ( 'D Crop' ),
            'D Crop'[CropKey] IN { 5767, 6014, 5408, 5769, 6015, 5438 }
        )
    VAR v2 = CALCULATETABLE ( DISTINCT ( 'D Crop'[Crop Abbrev] ), v1 )
    VAR v3 =
        CONCATENATEX (
            v2,
            'D Crop'[Crop Abbrev], ", ",
            'D Crop'[Crop Abbrev], ASC
        )
    EVALUATE
        v3