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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
LME
Frequent Visitor

Two Date Columns in a slicer using DAX

 Hello everyone,

 

This is my first time posting here and will be using this forum more. Now on to my question:

 

I have a requirement where I need to showcase a count between two columns using a timeline slicer. Both columns are Dates/Time format.

 

I need to basically count an occurence of a certain date or between two dates, between those two columns using OR and display that count in a card visual. Both columns are in the same table. I was able to get the code that works which is this one:

 

COUNTROWS(FILTER(Table, OR(Table[Date1] >= DATE(2023, 6, 1), Table[Date2] >= DATE(2023, 6, 1))))
 
Date1Date2
2023/08/08 11:55 AM 
2023/09/12 2:13 PM2023/09/12 8:00 AM
2023/07/31 3:12 PM 
2017/03/20 4:03 PM2023/06/01 8:00 AM
 
As you see, by using OR  it is detecting the cells between the two columns which have that specification and it brings back the full row and the count of rows of whichever cells between the two columns holds TRUE. But that is just me testing it out. I compared the value i got using Dynamics CRM filters and both the code and the filters applied in the CRM gave me the same value. To give more context it is "on or after" said date.
 
Now I need to implement this in a timeline slicer that has the "between" options for custom date changes. I am not sure how to go about this. 
 
Any help on how to go about this will be helpful.
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @LME ,

Please try:

Measure = 
VAR _min_date = MIN('Dates'[Date])
VAR _max_date = MAX('Dates'[Date])
VAR _result = 
CALCULATE(
    COUNTROWS('Table'),
    ('Table'[Date1]>=_min_date && 'Table'[Date1]<=_max_date)
    || ('Table'[Date2]>=_min_date && 'Table'[Date2]<=_max_date)
) + 0
RETURN
_result

vcgaomsft_0-1694754433818.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @LME ,

Please try:

Measure = 
VAR _min_date = MIN('Dates'[Date])
VAR _max_date = MAX('Dates'[Date])
VAR _result = 
CALCULATE(
    COUNTROWS('Table'),
    ('Table'[Date1]>=_min_date && 'Table'[Date1]<=_max_date)
    || ('Table'[Date2]>=_min_date && 'Table'[Date2]<=_max_date)
) + 0
RETURN
_result

vcgaomsft_0-1694754433818.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

amitchandak
Super User
Super User

@LME , Create an independent date table and use that in slicer 

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Date])
return
calculate( sum(Table[Value]), filter('Table', 'Table'[Date1] >=_max || 'Table'[Date2] >=_max))

 

 

Or refer, how to deal with two dates

Power BI Dax Measure- Allocate data between Range: https://youtu.be/O653vwLTUzM

HR Analytics - Employees as on Date : https://youtu.be/e6Y-l_JtCq4
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...
Power BI HR Active Employee Tenure Bucketing, and Hired, Terminated, and Active employees: https://youtu.be/fvgcx8QLqZU

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

Hey again, I don't understand this formula that you have presented namely: "Date1[date]" and "Table[value]". Date1 is a column and not a table and I am not sure what you mean by value.

 

I am just using one table called new_companyprofile which has two date columns called "Created on" and "Updated on". I want a slicer based on the time period between a certain date and a certain date, the card visual will change with a count of how many dates occured between the two columns in that date range using the OR operator. I have visuals in there too which changes based on the slicer.

 

In my current slicer, I am using the "Update Date" column so it is only counting that column. I want the slicer to count both the update date and created on column. Refer to my example above. I really appreciate this!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.