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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
Syndicate_Admin
Administrator
Administrator

Use Variable in Query

Hello, you can use a variable within a query, for example I have this data that I must change every week within many queries, so I want to change it only in one place and it is updated dynamically in the rest of the queries.

Here's the piece of data I want to pass to a variable or save it within the registry in a table:

Weeks = 44,45,46,47,48,49,50,51,52 ----------> Every week I add another one and as it is in many queries I want to change it only in one place and update it dynamically.

This is one of many queries that I want to use a

NO VARIABLE

******************************************

Tbl_AllMarkets = SUMMARIZE (
Data,Data[SEASON],
"BOXES", CALCULATE(SUM(Data[BOXES]), Data[WEEK] in {44,45,46,47,48,49,50,51,52})
)
********************************************
WITH VARIABLE

******************************************

Tbl_AllMarkets = SUMMARIZE (
Data,Data[SEASON],
"BOXES", CALCULATE(SUM(Data[BOXES]), Data[WEEK] in {Weeks})
)
*******************************************
I tried to do this when adding a new measure but it gives me a PLACEHOLDER error
Do you understand what I want to do?
1 ACCEPTED SOLUTION
v-weiyan1-msft
Community Support
Community Support

Hi @Syndicate_Admin ,

 

Based on your description,
You might consider creating a Calculated table.
Here is an example:
My Sample:

vweiyan1msft_0-1704943674823.png

WeeksTable = DATATABLE(
             "WeekNum", INTEGER, 
             {{44}, {45}, {46}, {47}, {48}, {49}, {50}, {51},{52}}
             )

vweiyan1msft_1-1704943710593.png

Use the created Calculated table in the following code, Result is as below.

Measure = CALCULATE(SUM('Table'[Sales]),
                    FILTER('Table','Table'[Week] IN VALUES(WeeksTable[WeekNum]))
                   )

vweiyan1msft_2-1704943763043.png

 

Best Regards,
Yulia Yan

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-weiyan1-msft
Community Support
Community Support

Hi @Syndicate_Admin ,

 

Based on your description,
You might consider creating a Calculated table.
Here is an example:
My Sample:

vweiyan1msft_0-1704943674823.png

WeeksTable = DATATABLE(
             "WeekNum", INTEGER, 
             {{44}, {45}, {46}, {47}, {48}, {49}, {50}, {51},{52}}
             )

vweiyan1msft_1-1704943710593.png

Use the created Calculated table in the following code, Result is as below.

Measure = CALCULATE(SUM('Table'[Sales]),
                    FILTER('Table','Table'[Week] IN VALUES(WeeksTable[WeekNum]))
                   )

vweiyan1msft_2-1704943763043.png

 

Best Regards,
Yulia Yan

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.