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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ccalobeto
Frequent Visitor

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
v-jayw-msft
Community Support
Community Support

Hi @ccalobeto ,

 

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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

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 

Hi @ccalobeto ,

 

"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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
ccalobeto
Frequent Visitor

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

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

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?

@ccalobeto 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 😕

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

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

 

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

 

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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