Forum Discussion

NSC7's avatar
NSC7
Icon for Helper I rankHelper I
2 years ago
Solved

SELECTEDVALUE on a slicer returning Blank

Hi,

 

I am using SELECTEDVALUE to create a Dynamic column, but Selected value is returning blank and because of that Switch function is not giving proper result.

 

IdenYear =

VAR SelYear= SELECTEDVALUE('Calendar'[Year2])
RETURN 
SelYear
 

 

Based on the selectedvalue from filter I want to retrun below custom column value.

IdenYear =
VAR SelYear= SELECTEDVALUE('Calendar'[Year2])
RETURN
SWITCH(TRUE(),SelYear='Calendar'[Year2],"Y",SelYear-1='Calendar'[Year2] && MONTH('Calendar'[Date])=12,"Y","N")

Thanks

  • Anonymous's avatar
    Anonymous
    2 years ago

    HI Ahmedx,

    AFAIK, current power bi does not support to create dynamic calculated column/table based on filter effects. They do not work on the same level and you can't use the child to effect its parent level.

    For this scenario, I think it should be related selectedvalue function itself. It not suitable to handle multiple values.
    When you selected on the slicer, it has match with multiple rows and will return blank if you not enabled the alternateResult option to process. (since calculate column not able to receiver the filter effects from slicer, its row contents show match with whole table records)

    SELECTEDVALUE function - DAX | Microsoft Learn

    Notice: the data level of power bi(from parent to child level)

    Database(external) -> query table(query, custom function, query parameters) -> data model table(table, calculate column/table) -> data view with virtual tables(measure, visual, filter, slicer)

    Regards,

    Xiaoxin Sheng

6 Replies

  • this is because you have the date as a hierarchy, you need to disable it and create separate columns for the year

     

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

      I am using Year2 column in the slicer and in selectedvalue.

       

      Year2 = 'Calendar'[Date].[Year]
       
      VAR SelYear= SELECTEDVALUE('Calendar'[Year2])
       
      I have also tried Year2 as Year2 = YEAR('Calendar'[Date]) but it still does not work.
      • Ahmedx's avatar
        Ahmedx
        Icon for Super User rankSuper User

        see how to disable hierarchies
        and create a year column like this
        Year = YEAR(Date[Date])