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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Date columns in IF function

Hi!

I have two date columns:

•dim_leads[meeting_date]
•dim_leads[closed_date]

What I want is to:

if dim_leads[closed_date] = BLANK(), 

then calculate the number of leads according to dim_leads[meeting_date], otherwise according to dim_leads[closed_date]. 

 

I've tried this:

 

 

IF(

    dim_leads[closed_date] = BLANK(),

    CALCULATE(

               DISTINCTCOUNT(dim_leads[id]),

               USERELATIONSHIP(dim_date[Date],      dim_leads[meeting_date])

,

    CALCULATE(

               DISTINCTCOUNT(dim_leads[id]),

               USERELATIONSHIP(dim_date[Date],      dim_leads[closed_date])

)

 

... but the thing is that it returns me the error because IF can not define a single value from date column and requires me to specify an aggregate which is not what i'm looking for. 

 

Can you help me with this, please? How can I combine IF function with date column in it?

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

Hi @Anonymous 

 

Please make a little bit change to your dax formula.

CountIdInMeasure =

IF (

    SELECTEDVALUE ( dim_leads[closed_date] ) = BLANK (),

    CALCULATE (

        DISTINCTCOUNT ( dim_leads[id] ),

        USERELATIONSHIP ( dim_date[Date], dim_leads[meeting_date] )

    ),

    CALCULATE (

        DISTINCTCOUNT ( dim_leads[id] ),

        USERELATIONSHIP ( dim_date[Date], dim_leads[closed_date] )

    )

)

 

Result will looks like this:

vcazhengmsft_0-1636614377512.png

Attached the pbix file as reference.

 

Best Regards,

Community Support Team _ Caiyun

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. If you still have problems on it, please feel free to let us know. Thanks a lot!

 

View solution in original post

3 REPLIES 3
v-cazheng-msft
Community Support
Community Support

Hi @Anonymous 

 

Please make a little bit change to your dax formula.

CountIdInMeasure =

IF (

    SELECTEDVALUE ( dim_leads[closed_date] ) = BLANK (),

    CALCULATE (

        DISTINCTCOUNT ( dim_leads[id] ),

        USERELATIONSHIP ( dim_date[Date], dim_leads[meeting_date] )

    ),

    CALCULATE (

        DISTINCTCOUNT ( dim_leads[id] ),

        USERELATIONSHIP ( dim_date[Date], dim_leads[closed_date] )

    )

)

 

Result will looks like this:

vcazhengmsft_0-1636614377512.png

Attached the pbix file as reference.

 

Best Regards,

Community Support Team _ Caiyun

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. If you still have problems on it, please feel free to let us know. Thanks a lot!

 

Anonymous
Not applicable

Hey, thank you so much, you really helped me out! I appreciate it a lot.

amitchandak
Super User
Super User

@Anonymous , Try like

 

CALCULATE(

DISTINCTCOUNT(dim_leads[id]),filter(dim_leads, isblank(dim_leads[closed_date])),
USERELATIONSHIP(dim_date[Date], dim_leads[meeting_date]) )
+
CALCULATE(

DISTINCTCOUNT(dim_leads[id]),filter(dim_leads, not(isblank(dim_leads[closed_date])) ),
USERELATIONSHIP(dim_date[Date], dim_leads[closed_date])

)

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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 MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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