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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

IF statement with Dates in a measure

Hey there,

 

I'd like to create a measure that will calculate something for me if it match some given criteria. For instance, in the following image I wanna create a measure that will count the number of rows if the filtered date is over 16/03/2022. However, when I do that DAX do not let me finish the formula.

pedrohp503_0-1649689961769.png

Just to make something clear, creating a calculated column is not an option because I need it to be dynamic.
What I wanna create whit this formula? If the date is on or after 16/03/2022, I'll not count some employees and to do so, I have created a measure with


var Excluded CALCULATE(COUNTROWS(Base), FILTER(Base, Base[assignee] <> "Someone"))
return IF(Calendario[Data] > 16/03/2022, Excluded, CALCULATE(COUNTROWS(Base)))

 

Thanks in advance!

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

Hi, @Anonymous 

 

Usually we use date() function when we use date.

measure =
IF (
    SELECTEDVALUE ( Calendario[Data] ) > DATE ( 2022, 3, 16 ),
    Excluded,
    CALCULATE ( COUNTROWS ( Base ) )
)

If your problem has been solved, you can mark the answer as solution to close the thread. If my post helps, please consider Accept it as the solution to help the other members find it more quickly. If not, please feel free to ask me.

 

Best Regards,
Community Support Team _ Janey

View solution in original post

6 REPLIES 6
v-janeyg-msft
Community Support
Community Support

Hi, @Anonymous 

 

Usually we use date() function when we use date.

measure =
IF (
    SELECTEDVALUE ( Calendario[Data] ) > DATE ( 2022, 3, 16 ),
    Excluded,
    CALCULATE ( COUNTROWS ( Base ) )
)

If your problem has been solved, you can mark the answer as solution to close the thread. If my post helps, please consider Accept it as the solution to help the other members find it more quickly. If not, please feel free to ask me.

 

Best Regards,
Community Support Team _ Janey

johnt75
Super User
Super User

You need to wrap Calendario[Data] inside a SELECTEDVALUE function.

Anonymous
Not applicable

Thanks for helping me.

I didn't understand how I have to create the formula. Could please show me?

Thanks in advance, buddy.

var Excluded CALCULATE(COUNTROWS(Base), FILTER(Base, Base[assignee] <> "Someone"))
return IF( SELECTEDVALUE(Calendario[Data]) > 16/03/2022, Excluded, CALCULATE(COUNTROWS(Base)))
amitchandak
Super User
Super User

@Anonymous , You can use a date slicer and filter date table from column or connected column. You can use before slicer

 

hard coded date will be like

var Excluded CALCULATE(COUNTROWS(Base), FILTER(Base, Base[assignee] <> "Someone"))
return IF(Calendario[Data] > Date(2022,03,16) , Excluded, CALCULATE(COUNTROWS(Base)))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thanks for the reply.

The problem is that when I type  IF(Calendario[Data] >, the Bi underline the function showing that it has an

error in the formula. What did you meant with the first part of your reply? You can use a date slicer and filter date table from column or connected column. You can use before slicer. I didn't get that.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.