Forum Discussion

breeze87's avatar
breeze87
Frequent Visitor
3 years ago
Solved

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.

 

Thanks in advance!

  • breeze87's avatar
    breeze87
    3 years ago

    Hey Anonymous,

     

    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

  • Anonymous's avatar
    Anonymous
    Not applicable

    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. 

    • breeze87's avatar
      breeze87
      Frequent Visitor

      Hey Anonymous,

       

      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!

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        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.