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
jnnilesh29
Helper III
Helper III

Filter Activities between a date range

Hi Everyone, 

 

I have a table with the list of activities with start date and finish date.

Please refer the table below:

 

jnnilesh29_0-1594324360814.png

 

I'm trying to create a lookahead schedule. For example, I want to list down the activities that fall under the date range of June 01, 2020 to June 30, 2020. Then again create the list of activities that fall under the date range of June 01, 2020 to July 31, 2020 and like wise for 5 months from June 01, 2020.

 

I did a lot of search and came up with the following code but it is not working . I may be completely wrong as I'm new with Power BI.

 

One Month Lookahead = 
VAR startdate = DATE(2020,06,01)
VAR finishdate = DATE(2020,06,30)
Return
SELECTEDVALUE('Activity Status'[Activity Name],FILTER('Activity Status','Activity Status'[Start]>=startdate &&'Activity Status'[Finish]<=finishdate))

 

 

Can somebody help me with this?

 

Appreciate your help in advance.

 

Reagrds,

Nilesh Jain

2 ACCEPTED SOLUTIONS
v-alq-msft
Community Support
Community Support

Hi, @jnnilesh29 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

 

Table:

e1.png

 

Calendar(a calculated table):

Calendar = CALENDARAUTO()

 

There is no relationship between two tables. You may create a measure as below.

Visual Control = 
var _min = CALCULATE(MIN('Calendar'[Date]),ALLSELECTED('Calendar'))
var _max = CALCULATE(MAX('Calendar'[Date]),ALLSELECTED('Calendar'))
var tab = 
SUMMARIZE(
    'Table',
    'Table'[Activity],
    'Table'[Start],
    'Table'[Finish],
    "flag",
    IF(
        NOT(
            OR(
                [Start]>_max,
                [Finish]<_min
            )
        ),
        1,0
    )
)
return
SUMX(
    tab,
    [flag]
)

 

Then you need to put the measure in the visual level filter and use the 'Date' column from 'Calendar' table to filter the result.

e2.png

 

e3.png

 

Best Regards

Allan

 

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

 

View solution in original post

Hello @jnnilesh29 

We can modify the measure a bit to turn off the relationship between the Dates table and the 'Activity Status' table just when doing the [Active Count] using CROSSFILTER:

Active Count No Join = 
CALCULATE(
    VAR _Start = FIRSTDATE ( DATES[Date] )
    VAR _End = LASTDATE ( DATES[Date] )
    RETURN
    CALCULATE(
        COUNTROWS('Activity Status'),
        'Activity Status'[Start] <= _End,
        'Activity Status'[End] >= _Start
    )
    ,CROSSFILTER('Activity Status'[Start],DATES[Date],None)
)

In my sample file the date table is linked and the normal count on catches the joined month, like you are seeing.  The updated meassure ignores the link when calculating so it returns on the months from start to finish. 

In the screenshot below the date slicer is filtering only the table below it and you can see that my date range is set to Feb 2019 and the table is showing all projects where the active period crosses Feb-2019.

jdbuchanan71_1-1594392021801.png

I have attached my sample file for you to look at.

 

View solution in original post

7 REPLIES 7
v-alq-msft
Community Support
Community Support

Hi, @jnnilesh29 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

 

Table:

e1.png

 

Calendar(a calculated table):

Calendar = CALENDARAUTO()

 

There is no relationship between two tables. You may create a measure as below.

Visual Control = 
var _min = CALCULATE(MIN('Calendar'[Date]),ALLSELECTED('Calendar'))
var _max = CALCULATE(MAX('Calendar'[Date]),ALLSELECTED('Calendar'))
var tab = 
SUMMARIZE(
    'Table',
    'Table'[Activity],
    'Table'[Start],
    'Table'[Finish],
    "flag",
    IF(
        NOT(
            OR(
                [Start]>_max,
                [Finish]<_min
            )
        ),
        1,0
    )
)
return
SUMX(
    tab,
    [flag]
)

 

Then you need to put the measure in the visual level filter and use the 'Date' column from 'Calendar' table to filter the result.

e2.png

 

e3.png

 

Best Regards

Allan

 

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

 

Hi Allan, 

 

Just to let you know, your solution also worked.

Thanks for your all efforts.

 

I appreciate your help.

 

Thanks and Regards,

Nilesh Jain

This is great. But I already have a calendar table connected to my activity table. 

Also, It would be greatly helpful if I can get the help to filter the activities that are either starting in June 2020 or finishing in June 2020. Using the date slicer for June 01, 2020 to June 30, 2020 does not capture the activties that are started before June 2020 or will be finishing after June 2020.

If needed, I can share my file with you and that way it would be easy for you to figure out.

 

Thanks and Regards,

Nilesh Jain

Hello @jnnilesh29 

We can modify the measure a bit to turn off the relationship between the Dates table and the 'Activity Status' table just when doing the [Active Count] using CROSSFILTER:

Active Count No Join = 
CALCULATE(
    VAR _Start = FIRSTDATE ( DATES[Date] )
    VAR _End = LASTDATE ( DATES[Date] )
    RETURN
    CALCULATE(
        COUNTROWS('Activity Status'),
        'Activity Status'[Start] <= _End,
        'Activity Status'[End] >= _Start
    )
    ,CROSSFILTER('Activity Status'[Start],DATES[Date],None)
)

In my sample file the date table is linked and the normal count on catches the joined month, like you are seeing.  The updated meassure ignores the link when calculating so it returns on the months from start to finish. 

In the screenshot below the date slicer is filtering only the table below it and you can see that my date range is set to Feb 2019 and the table is showing all projects where the active period crosses Feb-2019.

jdbuchanan71_1-1594392021801.png

I have attached my sample file for you to look at.

 

Genius. 

I really appreciate your efforts to put together the sample sheet. 

 

Thanks again!

 

Regads,

Nilesh Jain

jdbuchanan71
Super User
Super User

@jnnilesh29 

Can you share that sample in a table rather than a picture so we can copy and paste it? 

It will be something along these lines.

You will need a disconnected date table and that is what you will use to select your date range.

Then a measure like this to use as a filter.

Active Count:=
VAR MinDate = FIRSTDATE ( DATES[Date] ) 
VAR MaxDate = LASTDATE ( DATES[Date] ) 
RETURN
    CALCULATE (
        COUNTROWS(YourTable),
            YourTable[Finish] >= MinDate,
            YourTable[Start] <= MaxDate
    )

Then you apply that measure as a filter on your visual and set it to 'is not blank'

Thanks for your reply. 

 

The Calendar table in my file is connected to various columns in the Activity Status column. Disabling them is creating issue with other visuals. 

It would be greatly helpful if I can get the help to filter the activities that are either starting in June 2020 or finishing in June 2020. Using the date slicer for June 2020 does not capture the activties that are started before June 2020. 

If needed, I can share my file with you and that way it would be easy for you to figure out.

 

Thanks and Regards,

Nilesh Jain

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.