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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Dynamic Count

Hi all,
I need one help for a logic to implement in my PBI

I have date_open and date_close in my extract table

I need to count active case count based on date_open and date_close

The logic for active case count is like below:
Active is calculated by [date_open < month_start and date_close >= month_start] or [date_open < month_start and date_closed is blank] 

For example if we need to see active case count for october
If any case that were opened before october 1st and closed after october 1st is considered as active case in october

please help

Thanks in advance

21 REPLIES 21
v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

Can you provide sample data for testing? Sensitive information can be removed in advance. What kind of expected results do you expect? You can also show it with pictures or Excel. I look forward to your response.

 

Best Regards,

Community Support Team _Charlotte

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

Anonymous
Not applicable

Hi Zhangti,

MATTER_KEYOPEN_DATECLOSED_DATE
4052106/28/1994  
4392106/29/1994  


I am just providing little data, this two matters are opened in 1994 but not closed till date, then it will be counted as active date till 2023, we need to take it in count for each month of each year till date

Thanks in advance

Hi @Anonymous ,

 

I have added a new row to your data so we could have different results but see the measure below:

Active = 
COUNTROWS (
    FILTER (
        'Table',
        (
            'Table'[OPEN_DATE] <= MAX ( 'Calendar'[Date] )
                && 'Table'[CLOSED_DATE] >= max ( 'Calendar'[Date] )
        )
            || (
                'Table'[OPEN_DATE] <= Max ( 'Calendar'[Date] )
                    && 'Table'[CLOSED_DATE] = BLANK ()
            )
    )
)

You need to add a disconnected calendar table to your model:

MFelix_0-1698917089803.png

See file attach.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hi, can you please let me know how yoy have added only 1994 to 2023 years in calendar tabkle
beacuse when i am using same formula creating in my pbix file by using your calendar formula it's creating from 1992 to 2121, i don't know why

please help
Thanks

 

I'm using the CALENDARAUTO this picks up the min date on your dataset and the max date to get the first and last year if you want to close down the number of years try the following code instead of the calendarauto.:

 

CALENDAR("01/01/1994", DATE(YEAR(TODAY()),12, 31))

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hi ,
I am not getting correct count actually,
I'll share the snip of my pbix example output for may 2023 active matters
Active Data 2023 May.csv

So here the open dates below may 1st and closed date in may 


There is no information attached.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @Anonymous ,

 

Is this Active measure that I sent to you? Are you abble to share the PBIX file so I can check it if possible.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hello,

that's a manual data i pasted here from my data

From your pbix file, i have doubt that, the matters count for j2023 should be 3, because 1994 matters are not closed yet so count for them is 2 and matter in 2022 is closed in 2023 jan 5, so after 1st oif jan then it's considered as active matter for jan
so total 3 for year 2023 I guess,
please let me know on this

Hi @Anonymous ,

 

This depends on the context, when you look at 2023 overall the ones that are still open are the ones that started in 1994, at the end of the year the other one was closed in 5 th of january so it's closed.

 

Depending on the level of aggregation you are looking at the value is 2 or 3 even in 2023.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

so as per your data i want to count 3 in jan 2023
and in my logic if you see, open date should only be less than month_start not <=
can you please let me know exactly how to implement this please


Thanks in advance,

So to what I can understand when the case is closed, on that specific moth still counts as open right?

 

Redo the measure to:

Active = 
COUNTROWS (
    FILTER (
        'Table',
        (
            'Table'[OPEN_DATE] <= MAX ( 'Calendar'[Date] )
                && EOMONTH('Table'[CLOSED_DATE],0) >= max ( 'Calendar'[Date] )
        )
            || (
                'Table'[OPEN_DATE] <= Max ( 'Calendar'[Date] )
                    && 'Table'[CLOSED_DATE] = BLANK ()
            )
    )
)

MFelix_0-1698937436683.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

I will crealry exoplai

For example a matter is open in 28 april 2021, then it is closed on 5th may 2023

along with old matter keys it will add to older count like this

hope you understood

Then the matter_key for all these matters from may 2021 to may 2023
this will considered as active matter in each of the month after april 2021 till to may 2023

Then the measure that I have send out should work,

 

Because it's picking up the End of month and not the exact date of the close.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Active is calculated by [open_date < month_start and closed_date >= month_start] or [open_date < month_start and closed_date is blank] 
it should pick start of month based on above logic

can you please take a look

Thanks in advance

Try the following:

 

Active = 
COUNTROWS (
    FILTER (
        'Table',
        (
           EOMONTH('Table'[OPEN_DATE],-1) + 1 <= MAX ( 'Calendar'[Date] )
                && EOMONTH('Table'[CLOSED_DATE],0) >= max ( 'Calendar'[Date] )
        )
            || (
                           EOMONTH('Table'[OPEN_DATE],-1) + 1 <= Max ( 'Calendar'[Date] )
                    && 'Table'[CLOSED_DATE] = BLANK ()
            )
    )
)

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

So thankful for the help,

Here if I want to see the matter count which are closed in may 2023, then open date should be less than may 2023 ,

Please help
Thanks

Hi @Anonymous ,

 

Try the following code:

Closed = 
COUNTROWS (
    FILTER (
        'Table',
        (
            EOMONTH('Table'[OPEN_DATE], -1) + 1  <= MAX ( 'Calendar'[Date] )
                && EOMONTH('Table'[CLOSED_DATE],0)+1 <= MAX ( 'Calendar'[Date] )
        ) && 'Table'[CLOSED_DATE] <> BLANK()
            
    )
)

 

MFelix_0-1698998917734.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

ActiveNewOPEN_DATECLOSED_DATE
13/25/20205/1/2023
16/7/20225/1/2023
27/7/20225/1/2023
18/12/20225/1/2023
18/25/20225/1/2023
29/6/20225/1/2023
19/9/20225/1/2023
29/12/20225/1/2023
19/13/20225/1/2023
19/21/20225/1/2023
210/5/20225/1/2023
111/8/20225/1/2023
111/18/20225/1/2023
112/2/20225/1/2023
112/9/20225/1/2023
11/20/20235/1/2023
12/7/20235/1/2023
13/21/20235/1/2023
23/28/20235/1/2023
14/13/20235/1/2023
14/20/20235/1/2023
17/23/20185/2/2023
13/13/20205/2/2023
19/22/20225/2/2023
19/26/20225/2/2023
110/10/20225/2/2023
310/13/20225/2/2023
110/18/20225/2/2023
110/21/20225/2/2023
110/23/20225/2/2023
110/27/20225/2/2023
110/28/20225/2/2023
210/31/20225/2/2023
211/2/20225/2/2023
211/3/20225/2/2023
211/4/20225/2/2023
111/10/20225/2/2023
111/11/20225/2/2023
111/13/20225/2/2023
211/17/20225/2/2023
111/23/20225/2/2023
111/27/20225/2/2023
111/28/20225/2/2023
112/1/20225/2/2023
112/6/20225/2/2023
112/18/20225/2/2023
11/19/20235/2/2023
11/23/20235/2/2023
21/28/20235/2/2023
12/13/20235/2/2023
12/27/20235/2/2023
13/3/20235/2/2023
13/23/20235/2/2023
13/24/20235/2/2023
MFelix
Super User
Super User

Hi @Anonymous ,

 

Not sure how the model is setup but you will need to have something similar to this:

Active = COUNTROWS( FILTER( Table, (Table[date_open] <= Table[Month_Start] && Table[date_close] >=  Table [Month_start]) || (Table[date_open] <= Table[Month_Start] && Table[date_close] =   BLANK())

 

Be aware this is a generic measure and needs to be adjusted to your model.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors