Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
VerenaS
Frequent Visitor

Pass parameter to DAX Query within AnalysisServices.Database() statement

Hi all,

is is possible to pass a parameter to a DAX Query inside an AnalysisServices.Database() statement?

I have a Query like this:
= AnalysisServices.Database("Servername", "Databasename", [Query="DEFINE VAR ParamYear = 2014  EVALUATE ......... , Implementation="2.0"])

And I want to add a parameter "=@Year" to this query instead of inserting it like "=2014" as above. I already defined in PowerBI a parameter "Year" . How is it possible to pass the Power BI Year Parameter to the Query?
I want to avoid to query everything in the first step and set the filter in the second step, if it would be already possible to pass the parameter directly to this Query.....

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @VerenaS 

 

this record-field "Query" takes a text. So cou can hardcode it or use a parameter. Here an example how it could look like

ParYear = "2014"
GetAnalysis = AnalysisServices.Database("Servername", "Databasename", [Query="YourQuerText Year=" & ParYear & " EVALUATE ........." , Implementation="2.0"])

 

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

View solution in original post

3 REPLIES 3
castor
Frequent Visitor

Beware of code injection using this technique.

Jimmy801
Community Champion
Community Champion

Hello @VerenaS 

 

this record-field "Query" takes a text. So cou can hardcode it or use a parameter. Here an example how it could look like

ParYear = "2014"
GetAnalysis = AnalysisServices.Database("Servername", "Databasename", [Query="YourQuerText Year=" & ParYear & " EVALUATE ........." , Implementation="2.0"])

 

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

Thanks a lot for your help, Jimmy!

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.