Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago

DAX - How to check user segment filter selection ?

Hi,

 

I have a formula that is adaptive whenever the user select a country on the page or if no country selected (which is if the user want to see a zone).

To do this I simply check the filter like this :

IF(HASONEFILTER(COUNTRY[COUNTRY]);...;...)

This works well when I display my measure in a graph (bridge in this example). 

 

However this does not work when I display it in a grid where I also have the countries on rows. Indeed this would automatically compute the formula on one country and not by zone. 

 

How can I check the user filter only which is the selection made on the segment and ignore the row filter ?

 

Thanks for your help

3 Replies

  • v-lili6-msft's avatar
    v-lili6-msft
    Community Support

    hi, Anonymous 

    This involves the row context in DAX calculation.

    https://www.sqlbi.com/articles/row-context-and-filter-context-in-dax/

    For your case, just try this:

    If COUNTRY table is dim table, use [COUNTRY] field from data table in a gird, do not use  [COUNTRY] field from COUNTRY table.

     

    If COUNTRY table is not dim table, create a dim table, then create a relationship with Country table and use [COUNTRY] field from dim table in a gird.

     

    Here is a simple pbix file, please try it.

     

    Best Regards,

    Lin

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      COUNTRY is indeed a dim table but [COUNTRY] is not the key. It's a different hierarchy from the key that is linked to my data table. Therefore I cannot display the field from my data table.

      • v-lili6-msft's avatar
        v-lili6-msft
        Community Support

        hi, Anonymous 

        Could you share a simple sample pbix file with your expected output?

         

        Best Regards,

        Lin