cancel
Showing results for
Did you mean:

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Frequent Visitor

## Indices calculation with dynamic variable

Hi all!

I have this calculated column to see the price indices based on a fixed year (2018) and I'd like to be able to change that variable based on a manual input or a list of values.

I tried with field parameters, and a slicer from an unlinked table and it's been a struggle 😅

``````Index Jan 2018 100 =
VAR Yearbase = 2018
VAR Monthbase = 1
VAR feedstock = f_Feedstocks[Feedstock]
VAR numera = f_Feedstocks[Average M]
VAR denom =
CALCULATE(
AVERAGEX( f_Feedstocks, f_Feedstocks[Price] ),
FILTER( f_Feedstocks, f_Feedstocks[Feedstock] = feedstock ),
FILTER( f_Feedstocks, f_Feedstocks[Year] = Yearbase ),
FILTER( f_Feedstocks, f_Feedstocks[Month] = Monthbase )
)
VAR raw =
DIVIDE(
numera,
denom
)
RETURN
raw * 100``````

The table looks like this and it's doing the job fine for a predetermined year stored inside the variable.

1 ACCEPTED SOLUTION
Frequent Visitor

Hey @v-tangjie-msft,

One solution I will try is to have multiple columns calculated based on the years range and use a DAX measure to select the appropriate column to display based on the year selected but it will need to be unlinked from everything else.

``VAR Yearbase = 2018``

My intention, originally, was to have this number to be variable and not fixed.

Thanks for the feedback, I will leave the topic open for a couple of weeks and then accept your solution if nothing better shows up!

4 REPLIES 4
Community Support

Hi @breeze87 ,

According to your description, would you like to implement manual entry or select a certain year to filter your new columns?

For your problem, if you need to use slicers for filtering, then you can't use a new column, you should put the columns you need on top of the visual, and then write measures based on your logic, instead of calculated columns, which can't dynamically recognize slicer filtering. Second, you can also use the MAX() function to get the value selected by your slicer and apply it to your measure.

Best Regards,

Neeko Tang

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

Frequent Visitor

Hey @v-tangjie-msft,

One solution I will try is to have multiple columns calculated based on the years range and use a DAX measure to select the appropriate column to display based on the year selected but it will need to be unlinked from everything else.

``VAR Yearbase = 2018``

My intention, originally, was to have this number to be variable and not fixed.

Thanks for the feedback, I will leave the topic open for a couple of weeks and then accept your solution if nothing better shows up!

Community Support

Hi @breeze87 ,

Calculated columns are not dynamically aware of slicer filtering, try changing to a measure. and create a year table, create a slicer with the year table, change the variable to var Yearbase=selectedcolumn('for slicer',"Year",[Year]), and change the filter in the measure to FILTER( f_Feedstocks, f_Feedstocks[Year] In Yearbase ).

Best Regards,

Neeko Tang

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

Frequent Visitor

The Index page already has a Yearly slicer to show different timeframes.

I think it would defeat the highlited slicer purpose, so I went with the approach mentioned in my first reply. With the extra table to use as a slicer like you mentioned.

``````Index Calc new =
SWITCH(
TRUE(),
SELECTEDVALUE( 'Index Year'[Year] ) = 2018,
CALCULATE(
AVERAGEX( f_Feedstocks, f_Feedstocks[Index Jan 2018 100] ),
FILTER( f_Feedstocks, f_Feedstocks[View] <= [Selected View] )
),
SELECTEDVALUE( 'Index Year'[Year] ) = 2019,
CALCULATE(
AVERAGEX( f_Feedstocks, f_Feedstocks[Index Jan 2019 100] ),
FILTER( f_Feedstocks, f_Feedstocks[View] <= [Selected View] )
),
SELECTEDVALUE( 'Index Year'[Year] ) = 2020,
CALCULATE(
AVERAGEX( f_Feedstocks, f_Feedstocks[Index Jan 2020 100] ),
FILTER( f_Feedstocks, f_Feedstocks[View] <= [Selected View] )
),
SELECTEDVALUE( 'Index Year'[Year] ) = 2021,
CALCULATE(
AVERAGEX( f_Feedstocks, f_Feedstocks[Index Jan 2021 100] ),
FILTER( f_Feedstocks, f_Feedstocks[View] <= [Selected View] )
)
)``````

hopefully the extra calculated columns don't affect the performance too much 🙂

Thanks for the help @v-tangjie-msft

Announcements

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

#### Power BI Monthly Update - May 2024

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

#### Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors