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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
jeongkim
Post Prodigy
Post Prodigy

Count measure with conditions using VAR

Hi,

 

I need a measure to calculate with conditions that

 

Count: Internal Site ID

Condition 1: Category = NDPd

Condition 2: Site Creation(NDPd/IPM) = blank

Result= 23

 

jeongkim_0-1737607809598.png

 

My try is below and not resulting 23. still showing 32,561 total count of Internal Site ID.

Pls fix and suggest any simpler and better measure. 

 

NDPd Site Creation =
    VAR _count = COUNT('Distinct - Master Data'[Internal Site ID])
    VAR _filter = FILTER('Distinct - Master Data', 'Distinct - Master Data'[Category] = "NDPd" && 'Distinct - Master Data'[Site Creation(NDPd/IPM)] = BLANK())
    RETURN
        CALCULATE(_count, _filter)

 

jeongkim_1-1737607847166.png

 

3 ACCEPTED SOLUTIONS
anmolmalviya05
Super User
Super User

Hi @jeongkim, Please try the below measure:

NDPd Site Creation =
CALCULATE(
COUNTROWS('Distinct - Master Data'),
'Distinct - Master Data'[Category] = "NDPd",
ISBLANK('Distinct - Master Data'[Site Creation(NDPd/IPM)])
)

View solution in original post

Bibiano_Geraldo
Super User
Super User

Hi @jeongkim ,

You can achieve your goal by this DAX:

NDPd Site Creation = 
VAR _filter =
    FILTER(
        'Distinct - Master Data',
        'Distinct - Master Data'[Category] = "NDPd" &&
        ISBLANK('Distinct - Master Data'[Site Creation(NDPd/IPM)])
    )
RETURN
    CALCULATE(
        COUNT('Distinct - Master Data'[Internal Site ID]),
        _filter
    )

View solution in original post

Here you go

VAR _filter =
    FILTER (
        'Distinct - Master Data',
        'Distinct - Master Data'[Category] = "NDPd"
            && ISBLANK ( 'Distinct - Master Data'[Site Creation(NDPd/IPM)] )
    )
RETURN
    CALCULATE ( COUNTROWS ( 'Distinct - Master Data' ), _filter )


COUNTROWS - counts the number of rows in a table
COUNT - Counts the number of rows in the table where the specified column has a non-blank value

if there are no blanks in Internal Site ID column, the result will be the same





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

9 REPLIES 9
Bibiano_Geraldo
Super User
Super User

Hi @jeongkim ,

You can achieve your goal by this DAX:

NDPd Site Creation = 
VAR _filter =
    FILTER(
        'Distinct - Master Data',
        'Distinct - Master Data'[Category] = "NDPd" &&
        ISBLANK('Distinct - Master Data'[Site Creation(NDPd/IPM)])
    )
RETURN
    CALCULATE(
        COUNT('Distinct - Master Data'[Internal Site ID]),
        _filter
    )

This solution also works thanks!

anmolmalviya05
Super User
Super User

Hi @jeongkim, Please try the below measure:

NDPd Site Creation =
CALCULATE(
COUNTROWS('Distinct - Master Data'),
'Distinct - Master Data'[Category] = "NDPd",
ISBLANK('Distinct - Master Data'[Site Creation(NDPd/IPM)])
)

It works thanks! 

danextian
Super User
Super User

Hi @jeongkim 

To achieve a distinct count filtered by _filter in DAX using CALCULATE, you must use the complete expression defined in the variable, rather than the variable itself. DAX variables are immutable. Once they're assigned a value, they cannot be altered or reassigned within the same expression.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

any new dax suggestion pls? 

Just use the expression from the _count variable in CALCULATE after your RETURN statement.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

I dont' get it, can you write the code? 

Here you go

VAR _filter =
    FILTER (
        'Distinct - Master Data',
        'Distinct - Master Data'[Category] = "NDPd"
            && ISBLANK ( 'Distinct - Master Data'[Site Creation(NDPd/IPM)] )
    )
RETURN
    CALCULATE ( COUNTROWS ( 'Distinct - Master Data' ), _filter )


COUNTROWS - counts the number of rows in a table
COUNT - Counts the number of rows in the table where the specified column has a non-blank value

if there are no blanks in Internal Site ID column, the result will be the same





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

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.