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
KJanssens
Helper II
Helper II

Get count of records that were active on a specific date

I want to create a measure to calculate the number of records that were active on a specific date.

 

I came up with a measure like this:

 

NumberOfRecordsActiveOnDate = CALCULATE(DISTINCTCOUNT(mytable[ID]), FILTER(mytable, AND(mytable[createdon] <= RELATED(mydatetable[date]), mytable[deletedon] < RELATED(mydatetable[date])))

 

However, this does not return anything when I filter on a specific date...

any ideas?

 

thanks,

Koen

1 ACCEPTED SOLUTION

I just came accross the following post:

https://community.powerbi.com/t5/DAX-Commands-and-Tips/Active-records-over-time-based-on-Criteria/m-...

this will probably lead me in the right direction...

View solution in original post

5 REPLIES 5
marceloVVR
Helper I
Helper I

Well, if you understand how you need to filter an amount between data.
You will have two possibilities.

 

1- use the DATESBETWEEN function in filter
Example:

CALCULATE(DISTINCTCOUNT(table[ID]), FILTER(table, DATESBETWEEN(datetable[date],table[minDate],mytable[maxDate])))
 
2- Use the logical operators the same as you were doing, but changing the following locations:
CALCULATE(DISTINCTCOUNT(mytable[ID]), FILTER(mytable, (mydatetable[date] >=mytable[createdon]
&& mydatetable[date]<= mytable[deletedon] )))
 
test, if it does not solve let know.

I just came accross the following post:

https://community.powerbi.com/t5/DAX-Commands-and-Tips/Active-records-over-time-based-on-Criteria/m-...

this will probably lead me in the right direction...

@marceloVVR  should I have relations between the datetable and both datefields in my table?

like:

- datetable[date] 1----* mytable[startdate]

- datetable[date] 1----* mytable[enddate]

 

or doesn't that matter?

hi  @KJanssens 

For your case, it is a startdate and enddate problem, Very common. See this post about it:

https://community.powerbi.com/t5/Quick-Measures-Gallery/Periodic-Billing/m-p/409365

 

you don't need to create create two relationship with date table, just create a measure as this blog and use date field from calendar.

 

If you still have the problem, please share some sample date and your expected output.

 

Regards,

Lin

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

It doesn't matter, being data of the same type and use the FILTER before, as in the example I sent

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.