cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AndreLap
Resolver I
Resolver I

Calculate if value is between dates

Hello all, 

 

I already tried making this topic last week, but it seems to have vanished. 

I'm new to power BI and dax and could use some assistance. 

 

I have a table with cases something like the table below:

ID      createdate      closedate

1        01-01-17        15-02-17

2        02-01-17        10-01-17

3        03-01-17        null

 

The close date can be "null", meaning that the case is still open. I also created a date dimension table, with everything from year to days, there is no relation between the Date and Case table. 

 

I need an meassurement which will count all the "active" cases. Meaning that it will count all the cases that are open on a certain date. example: on the 9th of Januari (09-01-17) there are 3 cases active. On the 20th of januari (20-01-17) there are 2 cases active (1 and 3 in the example). 

 

Can you help me out? i have been trying different measurements and codes for a few days now!

 

Thank you very much in advance!

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi @AndreLap,

 

You may refer to my solution here.

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

11 REPLIES 11
Ashish_Mathur
Super User
Super User

Hi @AndreLap,

 

You may refer to my solution here.

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Works perfectly now. My bad for testing it the wrong way 

Good to hear.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Could you maybe explain how it works? Because i have trouble understanding the solution. 

Hi,

 

Have you tested the result? Does the solution work?  In the Query Editor, i have basically created a single column of dates from your start and end date columns.  So the query loaded to the Data Model has only 2 columns - ID and Date.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish, 

 

It seems to do what i want, but i cant test it yet in my enviroment. Can you explain "added custom 1" ({ Number.From([Createdate])..Number.From([Custom]) }) so that i can try to implement it in my enviroment? 

 

Thank you in advance!!

Hi,

 

That line creates a single column table with all dates from start to end for each ID.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

I understand now. I do get an error " The number is out of range of a 32 bit integer value Details: 42359.66638"

Any tips to fix that?

@AndreLap,

Ashish_Mathur's PBIX file works well in my environment. Would you please post complete data of your table for us to test?

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
miltenburger
Helper V
Helper V

Hi @AndreLap

 

First thing to do is, have a time slicer to select the date you want to see the information from. 

Next thing you do, create meausre:

active = CALCULTATE(COUNTROWS(tablename), closedata = "null")

Then select your date you want to see

hi @miltenburger,

 

Thank you for your answer. Unfortunatly this seems to return an error, and with some changes it only seem to retrieve cases that are currently open (closedate null). I'm looking for all the active cases of a day in history (the slicer was a good idea!). 

 

so it should only return cases for which:

create date <= [date selected] < end date  AND create date <= [date selected with end date = null.

 

Any further ideas? Cause it is greatly appriciated :)!

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors
Top Kudoed Authors