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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
leina_daniel
Regular Visitor

Injecting a Dynamic Variable into an Analysis Services Query for Filtering Analysis Serv. Cube Data

Hello Fabric Community,

I'm currently working with Analysis Services to query an anaylsis services cube and need some help with injecting a dynamic variable into the middle of my query. I have a weekly-updated list of budget codes that I want to use to filter my data, but I haven't been able to figure out how to properly incorporate this variable.

Below is an example of the query I'm working with the following DAX:
EVALUATE
// We want to get Var BC's from a different query
VAR BudgetCodes = {"TXP3GA182632","TXP3HQ01","TXP3HQ01D","TXP3HQ01GC","TXP3HQ01SPC"}
RETURN
SUMMARIZECOLUMNS(
'Dim PO Budget Code'[Budget Code],
'Dim Cost Center'[Cost Center Name],
'Dim Invoice Link'[Invoice Link],
KEEPFILTERS( TREATAS( BudgetCodes, 'Dim PO Budget Code'[Budget Code] )),
KEEPFILTERS( FILTER( ALL( 'Dim Cost Center'[Cost Center Code] ), NOT( ISBLANK( 'Dim Cost Center'[Cost Center Code] )))),
KEEPFILTERS( FILTER( ALL( 'Dim PO Budget Code'[Budget Code] ), 'Dim PO Budget Code'[Budget Code] <> "0" )),
"PO Ordered Amount Excluding Tax USD", [PO Ordered Amount Excluding Tax USD]
)
ORDER BY
'Dim PO Budget Code'[Budget Code] ASC,
'Dim Cost Center'[Cost Center Name] ASC,
'Dim Invoice Link'[Invoice Link] ASC

1 ACCEPTED SOLUTION

Thanks for sharing the update. Since your report uses DirectQuery, you can make budget code filtering dynamic without hardcoding it in your DAX query. 

 

1.Use a slicer linked to a budget codes table to filter the data dynamically.

2. If needed, set up Row-Level Security  in SSAS to restrict data based on user selection.

For an advanced option, you can try Dynamic M Query Parameters. This lets you filter directly in Power Query with parameters. Just make sure the Dynamic M Query Parameters feature is enabled under Options → Preview Features, and it's properly linked to your budget codes.

FYI:

Vyubandimsft_0-1742965118434.png

 

 

For more details, please refer to the following documentation.

Dynamic M query parameters in Power BI Desktop - Power BI | Microsoft Learn

Connect to Analysis Services data in Power BI Desktop - Power BI | Microsoft Learn

 

I hope this helps...

 

View solution in original post

8 REPLIES 8
V-yubandi-msft
Community Support
Community Support

Hi @leina_daniel ,

Has your issue been resolved, or do you require any further information? Your feedback is valuable to us. If the solution was effective, please mark it as 'Accepted Solution' to assist other community members experiencing the same issue.

V-yubandi-msft
Community Support
Community Support

Hi @leina_daniel ,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

V-yubandi-msft
Community Support
Community Support

Hi @leina_daniel ,

We noticed we haven't received a response from you yet, so we wanted to follow up and ensure the solution we provided addressed your issue. If you require any further assistance or have additional questions, please let us know.

Your feedback is valuable to us, and we look forward to hearing from you soon.

 

Thanks..

V-yubandi-msft
Community Support
Community Support

Hello @leina_daniel ,
Thanks for posting your query in the Microsoft Fabric Community. The approach to dynamically filtering budget codes depends on your connection mode in Power BI

1. Dynamic M Query Parameters work only in DirectQuery mode.
Dynamic M query parameters in Power BI Desktop - Power BI | Microsoft Learn

2. Dynamic M Query Parameters are NOT supported Live Connection

Instead, use slicers linked to a budget codes table or configure RLS in SSAS for filtering.

Connect to Analysis Services data in Power BI Desktop - Power BI | Microsoft Learn

 

Thanks for your continuous inputs for the community @lbendlin .

 

To provide the most accurate solution, could you confirm whether your report is using DirectQuery, or a Live Connection?

 

Regards,

Yugandhar.

The report uses a DirectQuery connection. Apologies for not clarifying sooner!

Thanks for sharing the update. Since your report uses DirectQuery, you can make budget code filtering dynamic without hardcoding it in your DAX query. 

 

1.Use a slicer linked to a budget codes table to filter the data dynamically.

2. If needed, set up Row-Level Security  in SSAS to restrict data based on user selection.

For an advanced option, you can try Dynamic M Query Parameters. This lets you filter directly in Power Query with parameters. Just make sure the Dynamic M Query Parameters feature is enabled under Options → Preview Features, and it's properly linked to your budget codes.

FYI:

Vyubandimsft_0-1742965118434.png

 

 

For more details, please refer to the following documentation.

Dynamic M query parameters in Power BI Desktop - Power BI | Microsoft Learn

Connect to Analysis Services data in Power BI Desktop - Power BI | Microsoft Learn

 

I hope this helps...

 

lbendlin
Super User
Super User

Dynamic M Query Parameters are only available for Direct Query data sources, not for live connections.

In this case, we are using a DirectQuery. Not a live connection

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.