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
mh0916
New Member

Dynamic reference instead of set text

Hello,

I am new to PowerBI and need some help please...

I am looking to dynamically refer to StyleCode column in my CALCULATETABLE formula, instead of only having set text of "FAR2I10". 

Can someone please assist?

Thanks

2016-12-12 (4).png

4 REPLIES 4
v-sihou-msft
Microsoft Employee
Microsoft Employee

@mh0916

 

In Power BI Desktop, we can't use Query Parameter in DAX formula.

 

@MattAllington is correct. In this scenario, it's not a good practice to hard code values for so many fields in your calculations. It's better to put those data fields into Slicer. Your measure will take your selection in slicer to calculate the corresponding result.

 

Regards,

 

 

Thanks all,

 

Can you set a slicer to auto adjust to always filter the last 6 months worth of dates or do you have to manually do this?

 

Much appreciated!

@mh0916

 

You may create a time period slicer in your report. Please refer to: POWER BI – TIME PERIOD SLICER FOR LAST 7 DAYS,LAST 30 DAYS.

 

Regards,

MattAllington
Community Champion
Community Champion

From what I can see in your image, you have some sort of slicer on the same text you are referring to. So just remove the text from your calculatetable statement. 

 

Also, I am sure there is a better way to do what you are doing an hard coding all that logic in your formulas.  Try to think about how you could reshape your data to do what you need.

 

The last 6 months portion should be pushed into a calendar table. The logic for the rest could be either managed before loading (i.e. Only load what's you need) or you could put a flag in the table to indicate if it should be included. Also, something like this would seem simpler

 

=calculate(Sum(table[qty]),filters)

 

also, try to simplify your table names. How about "Sales"



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

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.