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
Pbrit
Frequent Visitor

Calculate the count of Open status using date selection filter with DAX

I have an SA table that overrides the record when status changes from open to closed and vice versa, I have manged to get the changing data records using SSIS , now I want to count the records that have status open during a selected period using a date filter, sample table is below.

 

Explanation to Table:

SA: B was open from 20th jan 2023 to 25th jan 2023 and was closed, SA: D was open from 1st Feb 2023 to 5th Feb 2023 and was closed, the rest of the SA's status remained unchanged.

 

NoIdStartDateEndDateSAStatus
1115/01/2023 AOpen
2220/01/202325/01/2023BOpen
3325/01/2023 COpen
4401/02/202305/02/2023DOpen
5505/02/2023 EOpen
6225/01/2023 BClosed
7405/02/2023 DClosed

 

I Have the table above which contains SA, the status, the start date and end date,

I want to count the SA with status open when I do a date selection filter from 1st Jan 2023 to 31st Jan 2023,
what I expect for this count is No: 1,2,3 and for date selection filter from 1st Feb 2023 to 20th Feb 2023 is No 4 ,5.

 

I would appreciate any help on how to go about this as it has baffled me for long. If you require additional information, I would be glad to provide as well.

 

Thanks

12 REPLIES 12
Pbrit
Frequent Visitor

Good day @some_bih , Please can you see if you can help with this challenge I am facing. Thanks 

Hi @Pbrit please try measure below. Adjust your table name for Sheet2, and create Calendar / Date Table if you do not have it

Test =
VAR __start_date = MIN('Date'[Date])
VAR _end_date = MAX('Date'[Date])
VAR __selected_status = SELECTEDVALUE(Sheet2[Status])
RETURN
CALCULATE(
    DISTINCTCOUNT(Sheet2[SA]),--calculation of distinct count for SA
    FILTER(
        'Sheet2',
        'Sheet2'[Status] = __selected_status &&
        (
            'Sheet2'[EndDate] <= _end_date &&
            'Sheet2'[StartDate] >= __start_date
        )
    )
)
 
Output
some_bih_0-1694437561896.png

Did I answer your question? Kudos appreciated / accept solution!





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

Proud to be a Super User!






Thanks @some_bih for the fast response, is there a way to add ALL or any filter that would include the SA's that were open from say 1 Jan 2022 to 20 Feb 2023, when i choose 1st feb 2023 to 28th feb 2023 on the date filter.  with the current solution it only gives the sa open for the current month only.

Hi @Pbrit to reduce retesting please provide expected outpu for input





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

Proud to be a Super User!






@some_bih okay, Using the above code you provide , what i am expecting is if I select the period Feb 2023 with the date slicer, the output for open SA's should be 1000. 

 

DateOpen SA

Sept 2022

100
oct 2022120
Nov 2022200
Dec 2022250
Jan 2023200
Feb 2023130
Total1000

Hi @Pbrit I do not see amounts in your posting as input, so I can not tell what should be proposal for solution.





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

Proud to be a Super User!






@some_bih , The site scrumbled the table, Please find below

Using the above code you provide , what i am expecting is if I select the period Feb 2023 with the date slicer, the output for count of open SA's should be 1000.

 

Pbrit_0-1694531193748.png

 

Hi @Pbrit honestly, I do not undrestand, must be me. Where are INPUT data to get desired output, how That data is connected to your initial post...





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

Proud to be a Super User!






@some_bih , Please let me explain well,

From the previous solution you provide the input were below

 

NoIdStartDateEndDateSAStatus
1115/01/2023 AOpen
2220/01/202325/01/2023BOpen
3325/01/2023 COpen
4401/02/202305/02/2023DOpen
5505/02/2023 EOpen
6225/01/2023 BClosed
7405/02/2023 DClosed

 

 and you gave me this dax which will give the distinct number of SA's when I apply open status filter on with a selected date range eg 1jan2023 to 28feb2023.

Test =
VAR __start_date = MIN('Date'[Date])
VAR _end_date = MAX('Date'[Date])
VAR __selected_status = SELECTEDVALUE(Sheet2[Status])
RETURN
CALCULATE(
    DISTINCTCOUNT(Sheet2[SA]),--calculation of distinct count for SA
    FILTER(
        'Sheet2',
        'Sheet2'[Status] = __selected_status &&
        (
            'Sheet2'[EndDate] <= _end_date &&
            'Sheet2'[StartDate] >= __start_date
        )
    )
)
 
What i am asking is with this code , how can I get the distinct count of all SA's that are open from  1 Jan 2022 ( assuming this the earliest date of an SA) even though I chose 1 jan2023 to 28feb2023 in my date selection.
 
Please if it is still not clear , is there a way we can chat using this platform or if you dont mind sharing your whats app number.
Many Thanks



Hi @Pbrit Use new measure below, (row with SA = G added to test results, and in criteria fixed Status Open")

 

Test Status Open =
VAR __start_date = MIN('Date'[Date])
VAR _end_date = MAX('Date'[Date])
VAR __selected_status = SELECTEDVALUE(Sheet2[Status])
RETURN
CALCULATE(
    DISTINCTCOUNT(Sheet2[SA]),--calculation of distinct count for SA
    FILTER(
        'Sheet2',
        'Sheet2'[Status] = "Open" &&
        (
            'Sheet2'[EndDate] <= _end_date &&
            'Sheet2'[StartDate] >= __start_date
        )
    )
)

 

Output (no selection, row with SA = G added)

some_bih_0-1694585921790.png

Output (01.01.-28.02.2023): 5

some_bih_1-1694585998546.png

Output (13.02-1.6.07.2023): 1

 

some_bih_2-1694586075811.png

 

 





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

Proud to be a Super User!






ERD
Community Champion
Community Champion

Hi @Pbrit . You can try the measure

te1 =
VAR mindate = MIN ( 'Date'[Date] )
VAR maxdate = MAX ( 'Date'[Date] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Table__[SA] ),
        Table__[StartDate] >= mindate,
        Table__[StartDate] <= maxdate,
        'Table__'[Status] = "Open"
    )

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Pbrit
Frequent Visitor

@ERD , This couldn't help achieve the result, any other response would be appreciated

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.