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
laurent_rio
Helper I
Helper I

Filter in Union Function

Hi i have 3 tables 

 

1 is employee list 

Employee ID
1
2
3
4
5
6

 

2 is Employee Status 

Employee IDEmployee Status
1Active
3Active
4Terminated
5Active
7Active
8Terminated

 

 

I want to calculate total active employee based on table 1 and table 2 , the employee ID is distinct

My idea is use this function but i lost where i should put filter on table 2 where employee status = "active"

My Measure   =
    COUNTROWS (
        DISTINCT (
            UNION (
                VALUES ( Table1[EmployeeID] ),
                VALUES ( Table2[EmployeeID] ),
                           )
        )
    )

 

Please help

1 ACCEPTED SOLUTION
v-deddai1-msft
Community Support
Community Support

Hi @laurent_rio ,

 

Please use the following measure.

 

My Measure = CALCULATE(DISTINCTCOUNT('Employee ID'[Employee ID]),FILTER('Employee ID',LOOKUPVALUE('Employee Status'[Employee Status],'Employee Status'[Employee ID],'Employee ID'[Employee ID]) = "active"))

 

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

 

Best Regards,

Dedmon Dai

View solution in original post

3 REPLIES 3
v-deddai1-msft
Community Support
Community Support

Hi @laurent_rio ,

 

Please use the following measure.

 

My Measure = CALCULATE(DISTINCTCOUNT('Employee ID'[Employee ID]),FILTER('Employee ID',LOOKUPVALUE('Employee Status'[Employee Status],'Employee Status'[Employee ID],'Employee ID'[Employee ID]) = "active"))

 

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

 

Best Regards,

Dedmon Dai

AllisonKennedy
Super User
Super User

@laurent_rio  You don't need a UNION here - union will stack both tables on top of each other. 

 

Does the status table have each employee multiple times? Is there a date field to indicate the most recent entry and therefore current status? 

 

Are these two tables related in the data model?


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

amitchandak
Super User
Super User

@laurent_rio , You need to a common table

 

Employee ID  = DISTINCT (
UNION (
all ( Table1[EmployeeID] ),
all ( Table2[EmployeeID] ),
)
)

 

You can now join it with both table and get status from table 2 in visual

 

Or add a new column in Employee ID  table

 

maxx(filter(Table2, Table[Employee ID] = 'Employee ID'[Employee ID]), Table2[Employee Status])

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.