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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
rsanyoto
Helper III
Helper III

Ignore filters on all page based on measure and slicer

Hello all,

 

Currently  my visual doesnt working because of some wrong dax formula which i am currently using now.

 

Here's a short explaination based on the image below.

 

1. this visual uses the measure % Sales. Which has some IF(ISFILTERED) function. see my measure below this emage.

2. We need to filter out some values of the field Level 2 name from a slicer 

3. This filter is applied on this page.

 

 

Im guessing that the part of  IF(ISFILTERED) is the cause of the error.

 

 

Any suggestions ? should i rewrite the measure?  many thanks!

 

2021-06-24 16_22_18-MI Dashboard sprint 6 - Power BI Desktop (januari 2021).png

 

 

 

 

 

% sales =

VAR afdeling = 0

VAR directie = AVERAGE('Inhuur externen'[% Norm])

VAR kolom =

SWITCH(

    TRUE(),

        VALUES('MasterKeyTable'[Level 2 name]) = "DGV", 0.069,

        VALUES('MasterKeyTable'[Level 2 name]) = "DGCZ", 0.065,

        VALUES('MasterKeyTable'[Level 2 name]) = "DGLZ", 0.065,

        VALUES('MasterKeyTable'[Level 2 name]) = "plv. SG", 0.113,

        VALUES('MasterKeyTable'[Level 2 name]) = "SG", 0.065,

        VALUES('MasterKeyTable'[Level 2 name]) = "Overig kern", 0.061,

        VALUES('MasterKeyTable'[Level 2 name]) = "Agentschap CBG", 0.104,

        VALUES('MasterKeyTable'[Level 2 name]) = "Centrale Comm. Mensgebonden Onderzoek", 0.065,

        VALUES('MasterKeyTable'[Level 2 name]) = "CIBG", 0.28,

        VALUES('MasterKeyTable'[Level 2 name]) = "De Nederlandse Sportraad", 0.06,

        VALUES('MasterKeyTable'[Level 2 name]) = "Dienst Uitv. Subsidies aan Instellingen", 0.33,

        VALUES('MasterKeyTable'[Level 2 name]) = "Gezondheidsraad", 0.06,

        VALUES('MasterKeyTable'[Level 2 name]) = "IGJ", 0.09,

        VALUES('MasterKeyTable'[Level 2 name]) = "Projectdirectie ALT", 0.114,

        VALUES('MasterKeyTable'[Level 2 name]) = "Raad vd Volksgezondheid en Samenleving", 0.06,

        VALUES('MasterKeyTable'[Level 2 name]) = "Rijksinstituut RIVM", 0.10,

        VALUES('MasterKeyTable'[Level 2 name]) = "Sociaal En Cultureel Planbureau", 0.06,

BLANK())

VAR result =

IF(ISFILTERED('MasterKeyTable'[Level 4 name]),afdeling,

IF(ISFILTERED('MasterKeyTable'[Level 3 name]),directie,

IF(ISFILTERED('MasterKeyTable'[Level 2 name]),kolom,

0.1)))

RETURN result

 

 

 

 

 

 

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi , @rsanyoto ;

According to your description, I tested it and find you should change measure as follows:

% sales = 
VAR afdeling = 0
VAR directie =AVERAGE ( 'Inhuur externen'[% Norm] )
var kolom=SWITCH (
    MAX ( 'MasterKeyTable'[Level 2 name] ),
    "DGV", 0.069,
    "DGCZ", 0.065,
    "DGLZ", 0.065,
    "plv. SG", 0.113,
    "SG", 0.065,
    "Overig kern", 0.061,
    "Agentschap CBG", 0.104,
    "Centrale Comm. Mensgebonden Onderzoek", 0.065,
    "CIBG", 0.28,
    "De Nederlandse Sportraad", 0.06,
    "Dienst Uitv. Subsidies aan Instellingen", 0.33,
    "Gezondheidsraad", 0.06,
    "IGJ", 0.09,
    "Projectdirectie ALT", 0.114,
    "Raad vd Volksgezondheid en Samenleving", 0.06,
    "Rijksinstituut RIVM", 0.10,
    "Sociaal En Cultureel Planbureau", 0.06,
    BLANK ())
VAR result =
    IF (
        ISFILTERED ( 'MasterKeyTable'[Level 4 name] ),
        afdeling,
        IF (
            ISFILTERED ( 'MasterKeyTable'[Level 3 name] ),
            directie,
            IF (ISFILTERED(MasterKeyTable[Level 2 name]),kolom, 0.1 )))
RETURN
    result

The final output is shown below:

vyalanwumsft_0-1624871950723.png

The last thing you should note is that if [Level 2 Name] is filtered, it is equivalent to [Level 3 Name] and [Level 4 Name] being filtered, because they belong to the same table, so the result may be slightly different from what you want.

vyalanwumsft_1-1624872244273.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yalanwu-msft
Community Support
Community Support

Hi , @rsanyoto ;

According to your description, I tested it and find you should change measure as follows:

% sales = 
VAR afdeling = 0
VAR directie =AVERAGE ( 'Inhuur externen'[% Norm] )
var kolom=SWITCH (
    MAX ( 'MasterKeyTable'[Level 2 name] ),
    "DGV", 0.069,
    "DGCZ", 0.065,
    "DGLZ", 0.065,
    "plv. SG", 0.113,
    "SG", 0.065,
    "Overig kern", 0.061,
    "Agentschap CBG", 0.104,
    "Centrale Comm. Mensgebonden Onderzoek", 0.065,
    "CIBG", 0.28,
    "De Nederlandse Sportraad", 0.06,
    "Dienst Uitv. Subsidies aan Instellingen", 0.33,
    "Gezondheidsraad", 0.06,
    "IGJ", 0.09,
    "Projectdirectie ALT", 0.114,
    "Raad vd Volksgezondheid en Samenleving", 0.06,
    "Rijksinstituut RIVM", 0.10,
    "Sociaal En Cultureel Planbureau", 0.06,
    BLANK ())
VAR result =
    IF (
        ISFILTERED ( 'MasterKeyTable'[Level 4 name] ),
        afdeling,
        IF (
            ISFILTERED ( 'MasterKeyTable'[Level 3 name] ),
            directie,
            IF (ISFILTERED(MasterKeyTable[Level 2 name]),kolom, 0.1 )))
RETURN
    result

The final output is shown below:

vyalanwumsft_0-1624871950723.png

The last thing you should note is that if [Level 2 Name] is filtered, it is equivalent to [Level 3 Name] and [Level 4 Name] being filtered, because they belong to the same table, so the result may be slightly different from what you want.

vyalanwumsft_1-1624872244273.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

This is what code optimized for speed should look like:

% sales =
switch( TRUE(),

    ISFILTERED( 'MasterKeyTable'[Level 4 name] ),
        var afdeling = 0
        RETURN
            afdeling,
    
    ISFILTERED( 'MasterKeyTable'[Level 3 name] ), 
        var directie = AVERAGE( 'Inhuur externen'[% Norm] )
        RETURN 
            directie,
    
    // You can't use ISFILTERED here because
    // your old measure was using VALUES later on
    // and this function would return a table
    // with more than 1 value if the column were
    // filtered with more than 1 value. Hence your
    // comparisons in the old measure were not
    // possible with scalars. And that's why
    // you were getting an error which clearly
    // says that "a table of multiple values
    // was supplied where a single value was
    // expected."
    HASONEFILTER( 'MasterKeyTable'[Level 2 name] ), 
        var Level2name = 
            SELECTEDVALUE(
                'MasterKeyTable'[Level 2 name], 
                "Many Values Visible" 
            )
        VAR kolom =
            SWITCH( TRUE(),
                Level2Name in {"dgv"}, 0.069,
                Level2Name in { "DGCZ", "DGLZ", "SG",
                    "Centrale Comm. Mensgebonden Onderzoek"}, 0.065,
                Level2Name in {"plv. SG"}, 0.113,
                Level2Name in {"Overig kern"}, 0.061,
                Level2Name in {"Agentschap CBG"}, 0.104,
                Level2Name in {"CIBG"}, 0.28,
                Level2Name in { "De Nederlandse Sportraad",
                    "Gezondheidsraad",
                    "Raad vd Volksgezondheid en Samenleving",
                    "Sociaal En Cultureel Planbureau"}, 0.06,
                Level2Name in {"Dienst Uitv. Subsidies aan Instellingen"}, 0.33,
                Level2Name in {"IGJ"}, 0.09,
                Level2Name in {"Projectdirectie ALT"}, 0.114,
                Level2Name in {"Rijksinstituut RIVM"}, 0.10,
                
                // Safety net but should never happen due
                // to the guard clause of this branch (HASONEFILTER).
                Level2Name in {"Many Values Visible"}, -100000
            )
        return
            kolom,
    
    // This will be returned if none of the above
    // is true.
    0.1
)

 

amitchandak
Super User
Super User

@rsanyoto , Try  a measure like

 

% sales =

VAR afdeling = 0

VAR directie = AVERAGE('Inhuur externen'[% Norm])

VAR kolom =

SWITCH(

    TRUE(),

        MAX('MasterKeyTable'[Level 2 name]) = "DGV", 0.069,

        MAX('MasterKeyTable'[Level 2 name]) = "DGCZ", 0.065,

        MAX('MasterKeyTable'[Level 2 name]) = "DGLZ", 0.065,

        MAX('MasterKeyTable'[Level 2 name]) = "plv. SG", 0.113,

        MAX('MasterKeyTable'[Level 2 name]) = "SG", 0.065,

        MAX('MasterKeyTable'[Level 2 name]) = "Overig kern", 0.061,

        MAX('MasterKeyTable'[Level 2 name]) = "Agentschap CBG", 0.104,

        MAX('MasterKeyTable'[Level 2 name]) = "Centrale Comm. Mensgebonden Onderzoek", 0.065,

        MAX('MasterKeyTable'[Level 2 name]) = "CIBG", 0.28,

        MAX('MasterKeyTable'[Level 2 name]) = "De Nederlandse Sportraad", 0.06,

        MAX('MasterKeyTable'[Level 2 name]) = "Dienst Uitv. Subsidies aan Instellingen", 0.33,

        MAX('MasterKeyTable'[Level 2 name]) = "Gezondheidsraad", 0.06,

        MAX('MasterKeyTable'[Level 2 name]) = "IGJ", 0.09,

        MAX('MasterKeyTable'[Level 2 name]) = "Projectdirectie ALT", 0.114,

        MAX('MasterKeyTable'[Level 2 name]) = "Raad vd Volksgezondheid en Samenleving", 0.06,

        MAX('MasterKeyTable'[Level 2 name]) = "Rijksinstituut RIVM", 0.10,

        MAX('MasterKeyTable'[Level 2 name]) = "Sociaal En Cultureel Planbureau", 0.06,

BLANK())

VAR result =

IF(ISFILTERED('MasterKeyTable'[Level 4 name]),afdeling,

IF(ISFILTERED('MasterKeyTable'[Level 3 name]),directie,

IF(ISFILTERED('MasterKeyTable'[Level 2 name]),kolom,

0.1)))

RETURN result

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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