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

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

Reply
Anonymous
Not applicable

Problems creating calculated table from a slicer

Hello,

I've been stuck with this issue for hours and I need help understanding why this solution isn't working. 

 

What I want to solve is this: 

I have a large table and based on a dropdown isolated slicer select a single year to filter the Prep_Sales (2) table to deliver only the valid rows for the present year and the past year. Also, I want to display the filtered data in a line chart so I need some calculated columns and a relationship to my hierarchy table.

But for some reason, the slicer didn't get the year (on CurrentYear VAR) even the filter works if you put it manually. I made sure that Year is an integer value.

 

My script is the following 

Calculated Table from Prep_Sales (2) =
VAR CurrentYearSELECTEDVALUE('Years (slicer)'[Year])
RETURN
FILTER(
'Prep_Sales (2)',
'Prep_Sales (2)'[Year]= CurrentYear ||
('Prep_Sales (2)'[Year]= CurrentYear - 1 && 'Prep_Sales (2)'[CategoryAppend] = "Results")
)
 
My model 
Captura de Pantalla 2022-03-04 a la(s) 12.13.56.png
 
The report 
 
Captura de Pantalla 2022-03-04 a la(s) 12.14.31.png
 
Properties of the report
Captura de Pantalla 2022-03-04 a la(s) 12.22.44.png

 Please, help me solve this!
11 REPLIES 11
Anonymous
Not applicable

Hi @Anonymous ,

 

You could create a measure like below.

measure =
var sales_year = selectedvalue('Prep_Sales (2)'[Year])
var CurrentYear = SELECTEDVALUE('Years (slicer)'[Year])

return
IF( sales_year = CurrentYear || sales_year = CurrentYear-1,1,0)
Add this measure to visual filter set value = 1.

 

Best Regards,

Jay

Anonymous
Not applicable

I took it. But I can't maintain the colors because the category is on the legend.

So I have to get deep into this because I need some time calculations and Dax patterns to improve the design, and I think it is the right way to do this.

Thank you 

Anonymous
Not applicable

Hi @Anonymous ,

 

"But I can't maintain the colors because the category is on the legend."

You can set data color manually.

1.jpg

 

Best Regards,

Jay

Anonymous
Not applicable

Sharing the pbix file.

 

I want the things :
- Select a Year and a Metric

- The Line Chart will display the metric and year selected with 3 curves: Present Year, Quota, and Last Year.

- Keep the Line colors when you change the metric or year slicers, for example, red for Quota, blue for Present Year, and gray for Last Year.

 

https://drive.google.com/drive/folders/1NyodJ-pBQL2DQXk8XzChm4e0mimO4Nca?usp=sharing

 

Thanks for your time and patience,

Carlos

littlemojopuppy
Community Champion
Community Champion

@Anonymous are you saying that the calculated table doesn't recalculate based on slicer selection?

Anonymous
Not applicable

Yes. I've tried with SELECTEDVALUE('Years (slicer)'[Year]), INT(SELECTEDVALUE('Years (slicer)'[Year])) and CONVERT(SELECTEDVALUE('Years (slicer)'[Year]), INTEGER) but didn't work. Any light with this BI variable?

@Anonymous calculated tables and columns only recalculate when data is refreshed, not when slicers change.  What you're trying to do is not possible.  Sorry to be the bearer of bad news 😕

Anonymous
Not applicable

Thanks for your time. It seems that I will change something of this model. How can I handle this solution?

@Anonymous no worries...I'm just trying to run out the clock at work.  What are you trying to do?

Anonymous
Not applicable

 

I want to do these things:

- Select a Year and a Metric 

- In a Line Chart display the metric selected with 3 curves: Present Year, Quota, and Last Year (see the image above).

- Keep the Line colors when you change the metric or year, for example, red for Quota, blue for Present Year, and gray for Last Year.

 

Thanks

 

@Anonymous can you provide sample data in a pbix file to work with?

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.