Forum Discussion

Julia2023's avatar
Julia2023
Icon for Helper I rankHelper I
1 year ago
Solved

measure interacts with slicer

Hello everyone,

I’m trying to create a measure that dynamically interacts with my slicer and selects only the values chosen in the measure. I’ve written the measure below, but it doesn’t seem to return any selected values. Could you please help me troubleshoot this? 

Qtr Selector =
VAR CurrentQtrSelection = 
    CALCULATE(
        MAX('Date'[Sort]),
        FILTER(
            ALL('Date'),
            'Date'[Is Next Qtr +1] = "Yes"
        )
    )

RETURN
    IF(
        SELECTEDVALUE('Date'[Sort]) <= CurrentQtrSelection || SELECTEDVALUE('Date'[Sort]) > 99999,
        1,
        0
    )

 

  • Hi Julia2023 

    Measures are evaluated in the filter or query context - they don’t inherently have a row context. When you place a measure alongside a date column, the visual evaluates the measure for each date, so you can filter it down to either 1 or 0 - or for all the rows or visible rows of a column or table depending on the filter modifier applied (ALL, ALLSELECTED).

    However, in visuals where you can’t directly add dimensions (like KPIs, old-style cards, etc.) or when another dimension is being used, you’ll need to wrap the original measure inside a new one. That way, the measure can still be evaluated properly in the given context. For example:

    CALCULATE ( [sales], FILTER ( VALUES ( 'Date'[sort] ), [Qtr Selector] = 1 ) )
    

    Note: While the measure below will still work it is generally more expensive and is a best practice to filter a column instead of the whole table.

    CALCULATE ( [sales], FILTER ( 'Date', [Qtr Selector] = 1 ) )
    

     

  • Hi, Julia2023 here is some few case where your measure is not working or returning any results 

     

    •  SELECTEDVALUE('Date'[Sort]) it only works when there's a single value selected, so if you select more than one it will not work. 
    • And comparison > 99999 seems arbitrary and may not work as intended
      You can try this 
    Qtr Selector Fixed =
    VAR CurrentQtrSelection =
        CALCULATE(
            MAX('Date'[Sort]),
            FILTER(
                ALL('Date'),
                'Date'[Is Next Qtr +1] = "Yes"
            )
        )
    VAR CurrentSort = 
        IF(
            HASONEVALUE('Date'[Sort]),
            VALUES('Date'[Sort]),
            BLANK()
        )
    RETURN
    IF(
        NOT ISBLANK(CurrentSort) && 
        (CurrentSort <= CurrentQtrSelection || ISBLANK(CurrentQtrSelection)),
        1,
        0
    )

     

6 Replies

  • Hi Julia2023 ,

    It may not be possible to give the exact reason for this measure to not work without knowing the data. I don't see any issues with this DAX.

     

    However do check for the below thing in the SELECTEDVALUE() 

     

    " SELECTEDVALUE() returns a value only when a single value is present in the current filter context. So, for this measure to work as expected, 'Date'[Sort] should be part of the visual or slicer context where the measure is used. "

  • Hi Julia2023 

    Measures are evaluated in the filter or query context - they don’t inherently have a row context. When you place a measure alongside a date column, the visual evaluates the measure for each date, so you can filter it down to either 1 or 0 - or for all the rows or visible rows of a column or table depending on the filter modifier applied (ALL, ALLSELECTED).

    However, in visuals where you can’t directly add dimensions (like KPIs, old-style cards, etc.) or when another dimension is being used, you’ll need to wrap the original measure inside a new one. That way, the measure can still be evaluated properly in the given context. For example:

    CALCULATE ( [sales], FILTER ( VALUES ( 'Date'[sort] ), [Qtr Selector] = 1 ) )
    

    Note: While the measure below will still work it is generally more expensive and is a best practice to filter a column instead of the whole table.

    CALCULATE ( [sales], FILTER ( 'Date', [Qtr Selector] = 1 ) )
    

     

  • Royel's avatar
    Royel
    Icon for Super User rankSuper User

    Hi, Julia2023 here is some few case where your measure is not working or returning any results 

     

    •  SELECTEDVALUE('Date'[Sort]) it only works when there's a single value selected, so if you select more than one it will not work. 
    • And comparison > 99999 seems arbitrary and may not work as intended
      You can try this 
    Qtr Selector Fixed =
    VAR CurrentQtrSelection =
        CALCULATE(
            MAX('Date'[Sort]),
            FILTER(
                ALL('Date'),
                'Date'[Is Next Qtr +1] = "Yes"
            )
        )
    VAR CurrentSort = 
        IF(
            HASONEVALUE('Date'[Sort]),
            VALUES('Date'[Sort]),
            BLANK()
        )
    RETURN
    IF(
        NOT ISBLANK(CurrentSort) && 
        (CurrentSort <= CurrentQtrSelection || ISBLANK(CurrentQtrSelection)),
        1,
        0
    )

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Julia2023,

     

    Thank you for reaching out to the Microsoft Fabric Forum Community, and special thanks to Thejeswar, danextian and Royel   for prompt and helpful response.

     

    Just following up to see if the Responses provided by community members were helpful in addressing the issue. If one of the responses helped resolve your query, please consider marking it as the Accepted Solution. Feel free to reach out if you need any further clarification or assistance.

     

    Best regards,
    Prasanna Kumar

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Julia2023,

     

    Just following up to see if the Response provided was helpful in resolving your issue. Please feel free to let us know if you need any further assistance.

     

    Best regards,

    Prasanna Kumar

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Julia2023,

    Just following up to see if the Responses provided by community members were helpful in addressing the issue. If one of the responses helped resolve your query, please consider marking it as the Accepted Solution. Feel free to reach out if you need any further clarification or assistance.

     

    Best regards,
    Prasanna Kumar