Forum Discussion

Lukas90's avatar
Lukas90
New Member
1 year ago
Solved

DAX

Hi,

 

I need to write a measure that will be calculated on the chart only for the smaller of the selected years. That is, if I select 2023 and 2024 on the slicer, I only want to see the value for 2023 (i.e. one bar) on the chart. On the X axis there will still be 2023 and 2024 because they are needed for other measures. That is, I need remove one right, blue bar (gray is another measure that counts well).

 

Thanks!

 

 

  • yes you are right. The issue was due to an oversight on my part. you should write it as follows...

     

    var min_year = calculate( min ('date' [year]) , allselected ('date' [year]))

9 Replies

  • Hi Lukas90 

     

    you can update your measure as follows:

    measure _min :=

    var min_year = min ('date' [year]) (if you dont have dim date you should use all or allselected)

    return

    if (selectedvalue(year) = min_year , blue_measure , 0 )

     

    If this post helps, then I would appreciate a thumbs up and mark it as the solution to help the other members find it more quickly. 

    • Selva-Salimi's avatar
      Selva-Salimi
      Solution Sage

      Lukas90 

       

      so you should write it as follows:

      var min_year = calculate( min ('date' [year]) , allselected ('date' , 'date' [year]))

       

      If this post helps, then I would appreciate a thumbs up and mark it as the solution to help the other members find it more quickly. 

  • dk_dk's avatar
    dk_dk
    Super User

    Hi Lukas90 

    I have a half solution that works, but will keep all the years on the x axis visible at all times:

     

    SelectiveVis table has a Year column and two measures (Correct and Wrong, correct is the one you want to show on all years, wrong is the one you want to show only on the min year) based on 2 columns

    I create a separate table (yrhlp) that only has one year column.

    Then a third measure:

    HiddenMeasure =

    VAR minYear = MIN(yrhlp[yr])

    VAR val = CALCULATE([Wrong Measure],SelectiveVis[Year]=minYear)

    RETURN
    IF(MAX(SelectiveVis[Year])=minYear,val,"")



    Then configure relationship as follows:

     

     

    In your visual, use the year from SelectiveVis as the axis, but in your slicer use the year from yrhlp.


    Here is how it looks:

     

     

     

     

    Couldnt find a way to get rid of the blank 2022 column unfortunately. But in terms of showing the measure only on the min year, it does what you were after.

     

    Hope it helps a little!