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
a_gaisin
Frequent Visitor

Page filter gets ignored in measure

Hello, I’m quite new to Power Bi and DAX, and encountered a problem, when page filter is ignored when a measure is calculated.

I have a table with project numbers, for each project there exists a certain number of entries in the table. There’s also a page filter that filters only certain subset of projects. For filtered subset of projects I need to calculate the number of entries that have their value in column called “Code” equal to “ABC”.

To do it, I created the following measure:

Count ABC = CALCULATE(COUNT(Table[‘Code’]), Table[‘Code’]=“ABC”)

I also added the following measure that counts overall number of entries(with any code) for every filtered project:

Count # codes = COUNTROWS(Table)

Adding these two measures in Matrix visual gives the following result:

Capture1.PNG

Now, I’m trying to add a third measure, that is supposed to take values based on a value of Count ABC. In my case, it should be equal to 1 if value of Count ABC equals 1, and 0 otherwise.

Here’s the code:

Count ABC with IF = IF(CALCULATE(COUNT(Table[‘Code’]),Table[‘Code]=“ABC”)=1,1,0)

When added to a Matrix visual (see image excerpt below), this measure completely ignores the page filter, and computes values for a set of all projects.

Capture3.PNG

How can I force it to comply with the page filter?

Thank you very much for help.

1 ACCEPTED SOLUTION

@a_gaisin 

 

Try this 

Count ABC with IF =
VAR _initsymbol =
    DISTINCT ( symbol_type[init_symbol] )
VAR _projectids =
    CALCULATETABLE (
        DISTINCT ( 'Table'[project id] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[first_symbol]
                IN _initsymbol
        )
    )
VAR _count =
    CALCULATE (
        COUNT ( 'Table'[code] ),
        'Table'[code] = "ABC"
    )
VAR _result =
    IF (
        ISBLANK ( _count ),
        0,
        _count
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Table'[project id] )
            IN _projectids,
        _result,
        BLANK ()
    )



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂


Regards,
Nandu Krishna

View solution in original post

8 REPLIES 8
nandukrishnavs
Super User
Super User

@a_gaisin 

 

Try this 

Count ABC with IF =
VAR x =
    CALCULATE (
        COUNT ( 'Table'[Code] ),
        'Table'[Code] = "ABC"
    )
RETURN
    IF (
        x = 1,
        1,
        BLANK ()
    )



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂

 

Here is my latest blog

https://community.powerbi.com/t5/Community-Blog/Dynamic-Page-Navigation-Based-on-User-Login/ba-p/109...


Regards,
Nandu Krishna

It works with BLANK(), thank you!

But how to make it work if I want it to equal to 0 or any other value?

@a_gaisin Can you explain your latest question?


Regards,
Nandu Krishna

I want the measure equal to 0, not BLANK, in case of FALSE. How can I make it happen?

@a_gaisin  Please provide sample data and expected output


Regards,
Nandu Krishna

@nandukrishnavs , please take a look at this pbix file (google drive) https://drive.google.com/file/d/1QawaQQncB0k6eaTUbuuF22vN8nrCyyRY/view?usp=sharing

Expected output looks like this:Capture5.PNG

@a_gaisin 

 

Try this 

Count ABC with IF =
VAR _initsymbol =
    DISTINCT ( symbol_type[init_symbol] )
VAR _projectids =
    CALCULATETABLE (
        DISTINCT ( 'Table'[project id] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[first_symbol]
                IN _initsymbol
        )
    )
VAR _count =
    CALCULATE (
        COUNT ( 'Table'[code] ),
        'Table'[code] = "ABC"
    )
VAR _result =
    IF (
        ISBLANK ( _count ),
        0,
        _count
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Table'[project id] )
            IN _projectids,
        _result,
        BLANK ()
    )



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂


Regards,
Nandu Krishna

@nandukrishnavs thank you, it works!

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.

Top Solution Authors