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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
PBI_alma
Regular Visitor

period between two dates considering the date-filter

Hello all,

 

 

I have an issue that I hope you can help me with your expertise.

 

 

 

There is a table with the following columns and --> examples:

 

- Customer_ID --> ABC
- Start Status green as date1 -->2023-07-25
- End Status green as date2 --> 2023-09-05
- Activity Code --> 10

 

 

Now I would like to build a report that uses a period filter to see how many customers had status green and this or that activity code at some point in the period.

 

I have built in here two view period filters (date1, date 2) to define the period. --> 2023-08-01 - 2023-08-31

 

How do I write the DAX query to take into account each filter setting and get all the customers whose start date may also have been before or whose end date may have been after the consideration period? In the example, customer ABC would have had status green in the period, but would not be included in a simple filter setting.

 

 

Do you have any ideas how to solve this?

 

= calculate(Distinctcount(Customer_ID),....??

 

 

 

Thank you, and best regards

 

Alma

1 ACCEPTED SOLUTION

Hi @PBI_alma 

Number Customers with Green Status v2 =
VAR __start_date = MIN('Date'[Date])
VAR _end_date = MAX('Date'[Date])
VAR __selected_activity_code = SELECTEDVALUE(Sheet1[Activity Code])
RETURN
CALCULATE(
    DISTINCTCOUNT(Sheet1[Customer_ID]),--calculation of distinct count for Customer ID
    FILTER(
        'Sheet1',
        'Sheet1'[Activity Code] = __selected_activity_code &&
        (
            'Sheet1'[Start Status green] <= _end_date &&
            'Sheet1'[End Status green] >= __start_date
        )
    )
)

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

 
 
Output, with additional dummy data
some_bih_0-1694154571632.png

 





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

Proud to be a Super User!






View solution in original post

3 REPLIES 3
some_bih
Super User
Super User

Hi @PBI_alma 

From your example, I inserted into Excel and created measure, and Create Calendar / Date Table

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

Number Customers with Green Status =
VAR __start_date = MIN('Date'[Date])
VAR _end_date = MAX('Date'[Date])
VAR __selected_activity_code = SELECTEDVALUE(Sheet1[Activity Code])
RETURN
COUNTROWS(
    FILTER(
        'Sheet1',
        'Sheet1'[Activity Code] = __selected_activity_code &&
        (
            'Sheet1'[Start Status green] <= _end_date &&
            'Sheet1'[End Status green] >= __start_date
        )
    )
)

 

Output, July in period selected (1 customer)

some_bih_0-1694092723992.png

Output, October in period selected (none customer)

some_bih_1-1694092790506.png

 





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

Proud to be a Super User!






Hi,

 

thanks a lot! this looks very good. But I am sorry that I forgot to mention that the customer IDs are not distinct in the list, so I have to count the distinct IDs. I tried to include calculate(distinctcount( in the code, but it doesnt work - could you please help me one more time, in which part of the code I can include the distinct count? Thank you so much!

Hi @PBI_alma 

Number Customers with Green Status v2 =
VAR __start_date = MIN('Date'[Date])
VAR _end_date = MAX('Date'[Date])
VAR __selected_activity_code = SELECTEDVALUE(Sheet1[Activity Code])
RETURN
CALCULATE(
    DISTINCTCOUNT(Sheet1[Customer_ID]),--calculation of distinct count for Customer ID
    FILTER(
        'Sheet1',
        'Sheet1'[Activity Code] = __selected_activity_code &&
        (
            'Sheet1'[Start Status green] <= _end_date &&
            'Sheet1'[End Status green] >= __start_date
        )
    )
)

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

 
 
Output, with additional dummy data
some_bih_0-1694154571632.png

 





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

Proud to be a Super User!






Helpful resources

Announcements
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.