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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculate within the time frame

So here's an example of the dataset I am working on and need to calculate:

The count of tasks if the task falls under the date filter. The date table is connected to the "Start Date".

 

Task NameStart DateEnd Date
A11/1/20162/15/2016
A22/1/20164/16/2016
A33/1/20166/16/2016
A44/1/20168/16/2016
A55/1/2016 
A66/1/2016 
A77/1/2016 
A88/1/201610/17/2017

 

So let's assume I select May 01, 2016 to May 10, 2016 in the date filter, it should populate all the tasks that were ever open during those 10 days. In this case, it should populate A3, A4, A5. So count  = 5. I tried using running total calculation, but it ignores every task created before May 01, 2016. Any other logic can I implement?

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@Anonymous - See Open Tickets. https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364#M147


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

First you need to delete the relationship between the date table and the start date before making the calculation.If you wanna keep the relationship,you need to make a copy of date table to do the calculation.Otherwise the result will be influnced by the date filter.

After the preparatory work is done,create a measure as below:

 

Measure = 

SUMX(DISTINCT('Table'[Task Name]),CALCULATE(IF(IF (
            MAX ( 'Table'[Start Date] ) <= MIN ( 'Calendar'[Date] )
                && (
                    MAX ( 'Table'[End Date] ) >= MAX ( 'Calendar'[Date] )
                        || MAX ( 'Table'[End Date] ) = BLANK ()
                ),
            1,
            0
        )=1,IF(MAX('Table'[End Date])=BLANK(),1,2))))

 

Finally you will see:

Annotation 2020-06-02 153938.png

For the related .pbix file,pls click here.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

Anonymous
Not applicable

Hi @v-kelly-msft ,

I tried it. But it shows as blank when the filter is reset. It should show just simple count of (taskid) in that case because every task falls between those two dates.

Greg_Deckler
Super User
Super User

@Anonymous - See Open Tickets. https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364#M147


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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