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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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