jake
jake

Reputation: 5

How to check if no value is selected in a slicer perform a calculation

I have a slicer as follows

US
Brazil
Peru

i have two measures as follows

Measure_1 = SELECTEDVALUE('Table 1'[Country])

Measure_2=
CALCULATE( 
    COUNT('Table 2'[Country]), 
    FILTER( 
        'Table 2', 
        'Table 2'[Country] = [Measure_1] 
    ) 
)

this counts the countries in table 2 based on what i select on table slicer.

Table 1 structure

Country
US
Brazil
Peru

Table 2

country
    US
    US
    US
    Brazil
    Peru
    Peru

so if i click US on the slicer i get the result of Count=3 which is correct cause table 2 has 3 US countries

my question is if i dont select any countries from the slicer how do i count all the countries in table 2 so the output if nothing is selected should be count=6

I am not sure how to change Measure_2 to accommodate a selected value and when no values are selected

Upvotes: 0

Views: 1242

Answers (1)

mkRabbani
mkRabbani

Reputation: 16908

The requirement you explained, is the basic behavior of calculation. You even do not need to consider SELECTEDVALUES for calculation as this is causing the issue your case. You can simply create your measure_2 as below-

Measure_2 = COUNT('Table 2'[Country])

Remember, you need an established relation between table 1 and 2 using Country column.

Now, if you select a country from the slicer, the measure_2 will show the count for the selected country. And when you deselect all countries in the Slicer, the measure_2 will return the COUNT for all countries available in the table.

Lets just have a look that how it should work for different selection shown in the below image-

enter image description here

Upvotes: 1

Related Questions