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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
ScORE
Helper I
Helper I

How to count (SUM) dates in several columns

I have a table that contains 4 columns with scheduled dates in all of the columns.  I need to count how many times an OG has a a date scheduled before a timeframe.  I have over 200 rows and 12 OG's.  When looking at this example and counting all instances for one OG before 5/1/2017.   the result would be:

 

Milwaukee Operations 16

MInneapolis 7

 

I am new at Power BI and can not figure this out.  A measure or calculated column will do.  Thanks in advance!

 

OGSchedule.1Schedule.2Schedule.3Schedule.4
Milwaukee Operations1/12/20174/20/20177/20/2017 
Milwaukee Operations1/12/20174/20/20177/20/2017 
Milwaukee Operations1/12/20174/20/20177/20/2017 
Milwaukee Operations1/19/20174/4/20177/13/2017 
Milwaukee Operations1/19/20174/4/2017  
Milwaukee Operations1/19/20174/4/2017 4/25/2017 
Milwaukee Operations1/19/20174/4/2017  
Milwaukee Operations1/30/20176/1/2017  
Minneapolis Operations2/2/2017 8/1/2017  
Minneapolis Operations2/2/2017 3/1/2017 4/5/2017 5/1/2017
Minneapolis Operations2/7/20173/1/2017 4/1/20179/1/2017
1 ACCEPTED SOLUTION
MalS
Resolver III
Resolver III

I assume you want the cutoff date to be dynamic?

 

One way of doing it is to use a 'disconnected slicer'. There are lots of good resources out there about this if you want to read up on it (e.g. http://exceleratorbi.com.au/wp-content/uploads/2017/02/SQLSat_MattAllington_DisconnectedTablesInDAX.... )

 

Here are the steps:

 

1. Bring in your data into a new .pbix file

2. Create a calendar table in the file as well. It should have a 'Dates' field with all of the dates that you might want to use to define your timeframe. (There are several ways to do this, but you could just click on the New Table button and copy and paste the data in). Make sure there is no relationship between the data table and the Calendar table

3. Create these measures (your table name may differ):

 

Date Filter = MAX('Calendar'[Dates])

Sch 1 Count = CALCULATE(COUNT(Table1[Schedule.1]), FILTER(Table1, Table1[Schedule.1] <= [Date Filter]))

Sch 2 Count = CALCULATE(COUNT(Table1[Schedule.2]), FILTER(Table1, Table1[Schedule.2] <= [Date Filter]))

Sch 3 Count = CALCULATE(COUNT(Table1[Schedule.3]), FILTER(Table1, Table1[Schedule.3] <= [Date Filter]))

Sch 4 Count = CALCULATE(COUNT(Table1[Schedule.4]), FILTER(Table1, Table1[Schedule.4] <= [Date Filter]))

Total Count = [Sch 1 Count] + [Sch 2 Count] + [Sch 3 Count] + [Sch 4 Count]

Then add a filter using your Calendar[Dates] field.

 

Also add a table that includes the OC field and the Total Count field. 

 

Count.png

View solution in original post

3 REPLIES 3
MalS
Resolver III
Resolver III

I assume you want the cutoff date to be dynamic?

 

One way of doing it is to use a 'disconnected slicer'. There are lots of good resources out there about this if you want to read up on it (e.g. http://exceleratorbi.com.au/wp-content/uploads/2017/02/SQLSat_MattAllington_DisconnectedTablesInDAX.... )

 

Here are the steps:

 

1. Bring in your data into a new .pbix file

2. Create a calendar table in the file as well. It should have a 'Dates' field with all of the dates that you might want to use to define your timeframe. (There are several ways to do this, but you could just click on the New Table button and copy and paste the data in). Make sure there is no relationship between the data table and the Calendar table

3. Create these measures (your table name may differ):

 

Date Filter = MAX('Calendar'[Dates])

Sch 1 Count = CALCULATE(COUNT(Table1[Schedule.1]), FILTER(Table1, Table1[Schedule.1] <= [Date Filter]))

Sch 2 Count = CALCULATE(COUNT(Table1[Schedule.2]), FILTER(Table1, Table1[Schedule.2] <= [Date Filter]))

Sch 3 Count = CALCULATE(COUNT(Table1[Schedule.3]), FILTER(Table1, Table1[Schedule.3] <= [Date Filter]))

Sch 4 Count = CALCULATE(COUNT(Table1[Schedule.4]), FILTER(Table1, Table1[Schedule.4] <= [Date Filter]))

Total Count = [Sch 1 Count] + [Sch 2 Count] + [Sch 3 Count] + [Sch 4 Count]

Then add a filter using your Calendar[Dates] field.

 

Also add a table that includes the OC field and the Total Count field. 

 

Count.png

Thanks!  This helped me solve my issue.  

Oops - I used <= in the measures, when I think you just wanted <

 

Anyway, hopefully you get my point.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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