Forum Discussion

MRenwick's avatar
MRenwick
Frequent Visitor
4 years ago
Solved

Using a DAX query in power query and would like to reference a previous step

Hello, I'm using a DAX query to access analysis services in power query.  I'd like to reference a previous step as a filter.  In the below example, Instead of "US" in the TREATAS function, I'd lik...
  • smpa01's avatar
    4 years ago

    MRenwick   great Q. I had a similar situation .

     

    Can you try the following and see if it helps

     

    let

    Source = Excel.CurrentWorkbook(){[Name="CountryTable"]}[Content],

    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Country", type text}}),

    Country = #"Changed Type"{0}[Country],

    #"Text Filter" = AnalysisServices.Database("SERVER1\CUBE1", "Wholesale",

    [Query="/* START QUERY BUILDER */#(lf)

    EVALUATE#(lf)SUMMARIZECOLUMNS(#(lf)

    'Business Sector'[Country],#(lf)

    KEEPFILTERS( TREATAS( {"""&Country&"""}, 'Business Sector'[Country] )),#(lf)

    ""ERP Net Sls Qty"", [ERP Net Sls Qty]#(lf))#(lf)

    /* END QUERY BUILDER */", Implementation="2.0"])

    in

    #"Text Filter"

     

    or

     

    let

    Source = Excel.CurrentWorkbook(){[Name="CountryTable"]}[Content],

    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Country", type text}}),

    Country = #"Changed Type"{0}[Country],

    #"Text Filter" = AnalysisServices.Database("SERVER1\CUBE1", "Wholesale",

    [Query="/* START QUERY BUILDER */#(lf)

    EVALUATE#(lf)SUMMARIZECOLUMNS(#(lf)

    'Business Sector'[Country],#(lf)

    KEEPFILTERS( TREATAS( {"""&Text.From(Country)&"""}, 'Business Sector'[Country] )),#(lf)

    ""ERP Net Sls Qty"", [ERP Net Sls Qty]#(lf))#(lf)

    /* END QUERY BUILDER */", Implementation="2.0"])

    in

    #"Text Filter"