Forum Discussion

Cabbage_Baby's avatar
Cabbage_Baby
Frequent Visitor
1 year ago
Solved

Measure Not Working on Line Chart Y-Axis Maximum

Hi Power BI Experts, I could use some help with a DAX and visual interaction issue: I'm trying to create a dynamic Y-axis maximum for a line chart that responds to different levels of date granu...
  • OwenAuger's avatar
    1 year ago

    Hi Cabbage_Baby ,

    I recommend using a field parameter for selection of Week/Month/Year rather than bookmarks.

    You can then retrieve the selected field parameter within the Max Y-Axis measures.

     

    The problem with the bookmark method is that, at the "visual level" where the Max Y-Axis measure is evaluated, ISINSCOPE ( ... ) will always return false because there is no "hierarchy of levels" in that context. The hierarchy levels only exist for measures that are grouped by the axis fields, which is why the measure works in the matrix visual.

     

    As an example, I created a field parameter called Date Parameterand edited the calculated table expression slightly:

    Date Parameter = 
    {
        ( "Week", NAMEOF ( Calendar_Lookup[Start of Week] ), 0 ),
        ( "Month", NAMEOF ( Calendar_Lookup[Start of Month] ), 1 ),
        ( "Year", NAMEOF ( Calendar_Lookup[Start of Year] ), 2 )
    }

    Then updated Max Y-Axis to:

    Max Y-Axis = 
    VAR SelectedDateParameter =
        IF (
            COUNTROWS ( 'Date Parameter' ) = 1,
            SELECTCOLUMNS ( 'Date Parameter', 'Date Parameter'[Date Parameter] )
        )
    RETURN
        SWITCH (
            SelectedDateParameter,
            "Week", 10,
            "Month", 20,
            "Year", 30
        )

    Note that we cannot directly write SELECTEDVALUE ( 'Date Parameter'[Date Parameter] )

    (see here).

     

    Finally, replaced the bookmark navigator with a slicer on 'Date Parameter'[Date Parameter].

     

    I also recommend disabling Auto date/time.

     

    PBIX attached.

     

    Regards