Forum Discussion

orana's avatar
orana
Icon for Helper I rankHelper I
4 years ago
Solved

User determined variable in calculation

I'm looking to see if there is a way to take the difference between two variables  1. average sales in 2019 and 2020 for product B-A 2. sales in "x" year for product M-A, where "x" would be determined by the user looking at the dashboard (either 2019,2020,2021,2022,2023, etc.)

 

I've tried to create measures, but when I use a slicer to determine variable number 2, the slicer is also applied to variable 1. If I create a column, variables 1 and 2 are fixed, meaning I cannot change the sales year. 

 

Below is the measure I've created: 

Subtract sales avg 2019 & 2020 from Sales X year =Divide(CALCULATE(SUM('PL Portfolio'[Trace Units]), FILTER('PL Portfolio', 'PL Portfolio'[Fiscal Year] <= 2020 && 'PL Portfolio'[B & M] = "B - A")),2) - CALCULATE(sum('PL Portfolio'[Trace Units]), Filter(' PL Portfolio', 'Mckesson PL Portfolio'[B & M] = "M - A"))
  • Try changing the first calculate to this:

    CALCULATE(
        SUM( 'PL Portfolio'[Trace Units] ),
        'PL Portfolio'[Fiscal Year] <= 2020,
        ALL( 'PL Portfolio'[Fiscal Year] ),
        'PL Portfolio'[B & M] = "B - A"
    )

     

6 Replies

  • Hi orana !
    I dont know your code, but it seems that adding ALL( Date[Year] ) to variable 1 could fix the problem, adding this would make your varable 1 not be affected by your Year slicer. Make sure that the column you use on your slicer is the same that you use inside ALL().
    Let me know if this helps! If it is not clear enought, please make sure to provide us the code so its easier to solve the problem.

    • orana's avatar
      orana
      Icon for Helper I rankHelper I

      Hey Pablo ,

       

      I revised my post with the measure that I currently have. Let me know if this helps

       

      Best,

      Oscar

      • PabloDeheza's avatar
        PabloDeheza
        Icon for Solution Sage rankSolution Sage

        Try changing the first calculate to this:

        CALCULATE(
            SUM( 'PL Portfolio'[Trace Units] ),
            'PL Portfolio'[Fiscal Year] <= 2020,
            ALL( 'PL Portfolio'[Fiscal Year] ),
            'PL Portfolio'[B & M] = "B - A"
        )