Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Boeboey
Frequent Visitor

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:

2025-03-25 11 13 34.png

Without selecting any slicervalue, all translations are shown:

2025-03-25 11 13 42.png

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)

2025-03-25 11 15 45.png

 

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

1 ACCEPTED SOLUTION
Deku
Super User
Super 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] ) 
   )
)

 


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

View solution in original post

2 REPLIES 2
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
Super User
Super 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] ) 
   )
)

 


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.