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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

DAX: Filter Measure based, not understanding how to use the correct context (.PBIXincluded)

Hi guys,

 

I made a measure to use as a Filter on top of a visible to view only the Employees that are in service based on a specific Entry Date.

So Entry Date 10/1/2019 should only view Employees in service at that specific date.

 

File that includes all:

.PBIX File 

 

With the following measure works when EmployeeID is the unique record, when I set the measure as filter equal to 1 on the table visual. Unfortunately my EmployeeID isn't unique in the table: If Employees' names change, they get a new record with a new BeginDate and EndDate. Somehow this creates problems to be able to view the correct data. Down below I have 'Employee6' that has 3 records, and the measure below does not count a '1' for the third record of 'Employee6'.

PeriodFilter = 

var _Begin = min(Employees[BeginDate]) 
var _End = min(Employees[EndDate]) 

return 
if(
    ( _Begin <= min('Calendar'[Date]) && _Begin <= max('Calendar'[Date])) 
     && ( _End >= min('Calendar'[Date]) && _End >= max('Calendar'[Date]))
    ,1,0
)

 

Sample Data:

| Employee   | BeginDate  | EndDate    |
|------------|------------|------------|
| Employee1  | 1/30/2020  | 1/3/2021   |
| Employee2  | 9/20/2021  | 1/1/2022   |
| Employee3  | 1/3/2021   | 5/29/2021  |
| Employee4  | 7/5/2021   | 9/20/2021  |
| Employee5  | 11/10/2020 | 7/5/2021   |
| Employee6  | 1/30/2020  | 1/3/2021   |
| Employee6  | 1/4/2021   | 8/1/2021   |
| Employee6  | 8/2/2021   | 12/31/2099 |
| Employee7  | 7/5/2021   | 9/20/2021  |
| Employee8  | 1/5/2015   | 7/5/2021   |
| Employee9  | 9/20/2021  | 12/31/2099 |
| Employee10 | 1/1/2021   | 12/31/2099 |
| Employee11 | 9/8/2017   | 1/3/2021   |
| Employee12 | 1/3/2021   | 9/20/2021  |
| Employee13 | 7/5/2021   | 12/31/2099 |
| Employee14 | 1/5/2015   | 11/10/2020 |
| Employee15 | 1/30/2020  | 9/20/2021  |
| Employee16 | 1/1/2021   | 12/31/2099 |
| Employee17 | 1/5/2015   | 1/3/2021   |
| Employee18 | 9/20/2021  | 12/31/2099 |
| Employee19 | 1/3/2021   | 12/31/2099 |
| Employee20 | 11/10/2020 | 12/31/2099 |

 

Somehow it does show the correct result when I also drag fields 'BeginDate' and 'EndDate' in the Table. But I do not want to include those fields in the Table. Because it does work with those fields, I started to think I might need a SUMX function instead, that evaluates every record in the table, and gives me the '1' back for the 3rd record of Employee6, by using the following measure:

 

PeriodFilter_SUMX = 

var _Begin = min(Employees[BeginDate]) 
var _End = min(Employees[EndDate]) 

return 
SUMX(
    Employees,
    if(
    ( _Begin <= min('Calendar'[Date]) && _Begin <= max('Calendar'[Date])) && ( _End >= min('Calendar'[Date]) && _End >= max('Calendar'[Date]))
    ,1,0
    )
)

 

This also doesn't work, apart that it gives a higher total number when the Date fields are included in the table.

 

How can I circumvent this problem within a measure? Any suggestions?

 

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this measure expression instead.

 

PeriodFilterNew =
VAR MinDate =
    MIN ( 'Calendar'[Date] )
VAR MaxDate =
    MAX ( 'Calendar'[Date] )
VAR Result =
    COUNTROWS (
        FILTER (
            Employees,
            Employees[BeginDate] <= MaxDate
                && Employees[EndDate] >= MinDate
        )
    )
RETURN
    IF ( Result > 010 )

 

mahoneypat_0-1633089546880.png

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Works perfect, thanks! Though I don't really understand why this works, and my code does not.

mahoneypat
Microsoft Employee
Microsoft Employee

Please try this measure expression instead.

 

PeriodFilterNew =
VAR MinDate =
    MIN ( 'Calendar'[Date] )
VAR MaxDate =
    MAX ( 'Calendar'[Date] )
VAR Result =
    COUNTROWS (
        FILTER (
            Employees,
            Employees[BeginDate] <= MaxDate
                && Employees[EndDate] >= MinDate
        )
    )
RETURN
    IF ( Result > 010 )

 

mahoneypat_0-1633089546880.png

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.