Forum Discussion

Boeboey's avatar
Boeboey
Frequent Visitor
1 year ago
Solved

Filtering on USERCULTURE() if no language has been selected in slicer

Hi,

 

I have a table with "production functions" in different languages.

I would like to get the "production functions" in the language that is selected in the slicer or if no slicer value is slected, use the USERCULTURE language.

 

This is my measure:

SafetyCodes_Language = 
var SelectedLanguage = SWITCH(TRUE(),
    SELECTEDVALUE('Safety codes (2)'[Language])="en","en",
    SELECTEDVALUE('Safety codes (2)'[Language])="fr","fr",
    SELECTEDVALUE('Safety codes (2)'[Language])="nl","nl",
    SELECTEDVALUE('Safety codes (2)'[Language])="pl","pl",
    SELECTEDVALUE('Safety codes (2)'[Language])="ru","ru",
    LEFT(USERCULTURE(),2)
)
return CALCULATE(DISTINCTCOUNT('info_HGR unpivoted'[Index]),'Safety codes (2)'[Language]=SelectedLanguage)

If a language is selected in the slicer, the filtering is done correctly:

Without selecting any slicervalue, all translations are shown:

When changing the measure to get the USERCULTURE directly, the filtering is also done correctly:

SafetyCodes_Language = 
var SelectedLanguage = LEFT(USERCULTURE(),2)
return CALCULATE(DISTINCTCOUNT('info_HGR unpivoted'[Index]),'Safety codes (2)'[Language]=SelectedLanguage)

 

I don't see why the first measure is not working as expected.

  • I assume the y axis is from the 'Safety codes (2)' table? In which case there is a single value per row. Try 

    SafetyCodes_Language = 
    IF( 
       ISFILTERED( SELECTEDVALUE('Safety codes (2)'[Language]) ),
       // IF filtered show all selected languages
       DISTINCTCOUNT( 'info_HGR unpivoted'[Index] ),
       // If no filter use user's language
       CALCULATE(
          DISTINCTCOUNT('info_HGR unpivoted'[Index]),
          TREATAS'( { LEFT(USERCULTURE(),2) }, 'Safety codes (2)'[Language] ) 
       )
    )

     

2 Replies

  • Boeboey's avatar
    Boeboey
    Frequent Visitor

    Awesome! Thanks Deku , it's working now. Made a small adaptation to your code:

    SafetyCodes_Language = 
    IF( 
       ISFILTERED('Safety codes (2)'[Language]),
       // IF filtered show all selected languages
       DISTINCTCOUNT( 'info_HGR unpivoted'[Index] ),
       // If no filter use user's language
       CALCULATE(DISTINCTCOUNT('info_HGR unpivoted'[Index]),'Safety codes (2)'[Language]=LEFT(USERCULTURE(),2))
    )

     Thanks for the quick support.

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

    I assume the y axis is from the 'Safety codes (2)' table? In which case there is a single value per row. Try 

    SafetyCodes_Language = 
    IF( 
       ISFILTERED( SELECTEDVALUE('Safety codes (2)'[Language]) ),
       // IF filtered show all selected languages
       DISTINCTCOUNT( 'info_HGR unpivoted'[Index] ),
       // If no filter use user's language
       CALCULATE(
          DISTINCTCOUNT('info_HGR unpivoted'[Index]),
          TREATAS'( { LEFT(USERCULTURE(),2) }, 'Safety codes (2)'[Language] ) 
       )
    )