Forum Discussion

jeseng's avatar
jeseng
Helper III
5 years ago

Comparing line chart

Hi,
I have a line chart, my users choose an area from a slicer. The line chart then shows the population growth for this area.
What I want is to show a second line, an other area (Göteborg) to compare to the chosen one. So I want one line that the user choose and one that is always there. But it doesnt seem to be possible to preselect a locked value?

12 Replies

  • jeseng , Try a measure like

    calculate([measure], filter(all(Table[area]), table[area] ="Göteborg"))

     

    But this will work better if the area is in a different table joined to this table

     

    calculate([measure], filter(all(area), area[area] ="Göteborg"))

    • jeseng's avatar
      jeseng
      Helper III

      Okey, and where do I put this measure? 🙂

      • amitchandak's avatar
        amitchandak
        Super User

        jeseng , You original measure and [measure] and this new measure both should be added to values/line

  • jeseng ,

    Create a measure like below for a constant line:

    Measure = CALCULATE(SUM('Table'[Growth]),FILTER(ALL('Table'),'Table'[AreaName]="Göteborg"))
     
    • jeseng's avatar
      jeseng
      Helper III

      Where do I put this measure?
      As you can se below:
      I have YEAR om my axis, then the AREA (which is in i slicer that my user can choose one area from) and the my value (from a column i my datatable) that is growth in percentage. Where do I put the measure?

      • Tahreem24's avatar
        Tahreem24
        Super User

        jeseng ,

        Which visual are you using?

        I can able to add measure under values option.

         

    • jeseng's avatar
      jeseng
      Helper III

      Hi again,

      When I removed the variable from "legend" I was able to put my measure in "values". The thing is, I dont want a constant line 🙂 I want to show the values for "Göteborg" as well as one more area, which my user can select from a slicer. My user also chooses Age and Gender in slicers.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  jeseng  ,

    According to your description, I create this data:

    Main Table:

    Slice Table:

    Here are the steps you can follow:

    1. Create calculated column.

    Year = YEAR('Table'[date])

    2. Create measure.

    A =
    var _1=
    CALCULATE(SUM('Table'[people]),FILTER('Table',[region]="A"))
    return
    IF("A" in SELECTCOLUMNS('Slicer',"1",[Region]),_1,BLANK())
    B =
    var _1=
    CALCULATE(SUM('Table'[people]),FILTER('Table',[region]="B"))
    return
    IF("B" in SELECTCOLUMNS('Slicer',"1",[Region]),_1,BLANK())

    3. Place Year in Axis, measure A and measure B in Values, and place Region and Sex in different slicers

    4. Result.

    When we select Region A, only the data of A will be displayed in the line chart, and it will change with the selection of the slicer Sex

    You can downloaded PBIX file from here.

     

    Best Regards,

    Liu Yang

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

    • jeseng's avatar
      jeseng
      Helper III

      Thank you so much for taking your time with this!! But I seem to be explaining poorly 😉
      I live in Gothenburg, we have 36 sub areas. I want a line chart where I can ALWAYS see the development for Gothenburg and then from a slicer choose ONE sub area. So that I always show 2 line, one that is locked (Gothenburg) and one that the user chooses.
      There will also be a slicer for Age and Gender but that doesn't seem to be the main problem.
      I CAN solve this in my datatable by creating a new column with the values for Gothenburg and put this on every row, so that every sub area have two values, but this will be difficult to update since I plan to collect the data via API....

      Best Regards,
      Jessica

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  jeseng  ,

    According to your description, I create this data:

     

    Here are the steps you can follow:

    1. Create measure.

    Locked in (Gothenburg) development:

    Gothenburg region all =
    SUMX(FILTER(ALL('Table'),'Table'[Year]=MAX('Table'[Year])),'Table'[people])

    User selected:

    User chooise =
    var _select=SELECTEDVALUE('Slicer'[Region])
    var _1=CALCULATE(SUM('Table'[people]),FILTER('Table','Table'[Gothenburg region]=_select&&'Table'[Year]=MAX('Table'[Year])))
    return _1

    2. Result.

     

    You can downloaded PBIX file from here.

     

    Best Regards,

    Liu Yang

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