The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hi there
Love PowerQuery, but for some reason I can't get my head around DAX.
Anyway - I have an Employee table where I have an employment start and termination date listed. For any given period I'd like to calculate the number of days the worker has been employed, taking the start and termination dates into account.
So far I have the below, but a few issues...
1) It complains about my True/False expression. What am I doing wrong here?
2) How can I deduct 1 day from STDATE_EMP (when used in EXCL_DAYS)? Tried using DATEADD but it was expecting a column?
3) The SELECTEDRANGE is right now a single column table. Can I somehow filter this? I'm thinking a combination of VALUES and FILTER...?
Sorry that's a lot but really struggling.
Solved! Go to Solution.
The below assumes that you have a column called Is Working Day in your date table, which contains a 1 if it is a working day and 0 otherwise.
Employed days =
SUMX (
Employee,
VAR StartDate = Employee[Start date]
VAR EndDate = Employee[Termination date]
VAR NumDays =
CALCULATE (
SUM ( 'Date'[Is Working Day] ),
KEEPFILTERS ( DATESBETWEEN ( 'Date'[Date], StartDate, EndDate ) )
)
RETURN
NumDays
)
Thanks so much! Really appreciate it.
The below assumes that you have a column called Is Working Day in your date table, which contains a 1 if it is a working day and 0 otherwise.
Employed days =
SUMX (
Employee,
VAR StartDate = Employee[Start date]
VAR EndDate = Employee[Termination date]
VAR NumDays =
CALCULATE (
SUM ( 'Date'[Is Working Day] ),
KEEPFILTERS ( DATESBETWEEN ( 'Date'[Date], StartDate, EndDate ) )
)
RETURN
NumDays
)
User | Count |
---|---|
15 | |
12 | |
8 | |
7 | |
7 |
User | Count |
---|---|
24 | |
21 | |
12 | |
10 | |
7 |