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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors