cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
suhasakole
Frequent Visitor

SQL to DAX Measure

I am planning to create DAX calculated measure in the PowerBI where Date will be passed as a slicer for the measure and it should return the current headcount of the employee. 

SELECT 

COUNT(DISTINCT A.emplid) AS HEADCOUNT 
FROM 
tbl_EmpHistory  AS A
Inner join (SELECT emplid, MAX(WorkStartedDate) as WorkStartedDate
                  FROM tbl_EmpHistory 
                  Where WorkStartedDate <=  cast('2017-12-31' as Date) -- this data will pass as slicer from PowerBI Dashboard 
            Group by  emplid ) AS B
ON A.emplid = B.emplid
AND A.WorkStartedDate = B.WorkStartedDate
WHERE 
lower(A.type) = 'emp' 

AND A.active = 1

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

@suhasakole ,

 

You may take a look at the links below.

Community Support Team _ Sam Zha
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

3 REPLIES 3
v-chuncz-msft
Community Support
Community Support

@suhasakole ,

 

You may take a look at the links below.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

thanks

suhasakole
Frequent Visitor

any help ... much appreciated


@suhasakole wrote:

I am planning to create DAX calculated measure in the PowerBI where Date will be passed as a slicer for the measure and it should return the current headcount of the employee. 

SELECT 

COUNT(DISTINCT A.emplid) AS HEADCOUNT 
FROM 
tbl_EmpHistory  AS A
Inner join (SELECT emplid, MAX(WorkStartedDate) as WorkStartedDate
                  FROM tbl_EmpHistory 
                  Where WorkStartedDate <=  cast('2017-12-31' as Date) -- this data will pass as slicer from PowerBI Dashboard 
            Group by  emplid ) AS B
ON A.emplid = B.emplid
AND A.WorkStartedDate = B.WorkStartedDate
WHERE 
lower(A.type) = 'emp' 

AND A.active = 1



 

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors