Forum Discussion
Help needed for counting dates for a calculated column.
Hi all,
I'm working with a large dataset of Employee numbers, dates, and statuses Here is an example of what it looks like (it continues for around a million rows):
What I want to do is to make a calculated column with a binary value of '1' or '0'. Where it shows 1 if that particular employee number has NOT had StatusCode NORMAL TIME at any point in the last 6 weeks.
Example:
I've taken a stab at it and here is the code that I've got so far, but I'm not sure its correct...
SixWeekFlag =
IF (
CALCULATE (
COUNTROWS ( Actual ),
FILTER (
ALLEXCEPT(Actual, Actual[EmployeeNumber]),
Actual[StatusCode] = "NORMAL TIME"
),
DATESINPERIOD (
Actual[Date],
LASTDATE ( Actual[Date] ),
-42, ) ) = 0, 1, 0)
Any ideas? Help is much appreciated.
- Anonymous2 years ago
Hi lbendlin ,thanks for the quick reply, I'll add further.
Hi Natrify ,
The Table data is shown below:
Please follow these steps:
1. Use the following DAX expression to create a columnColumn = IF( COUNTROWS(FILTER('Table','Table'[Date]< EARLIER('Table'[Date]) && 'Table'[Date] >= EARLIER('Table'[Date]) - 42 && 'Table'[StatysCode] = "NORMAL TIME" &&'Table'[Employeenumber] = EARLIER('Table'[Employeenumber]))) <> 1, 1,0)2.Final output
Best Regards,
Wenbin Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- lbendlinSuper User
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information or anything not related to the issue or question.
If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
Please show the expected outcome based on the sample data you provided.
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523 - AnonymousNot applicable
Hi lbendlin ,thanks for the quick reply, I'll add further.
Hi Natrify ,
The Table data is shown below:
Please follow these steps:
1. Use the following DAX expression to create a columnColumn = IF( COUNTROWS(FILTER('Table','Table'[Date]< EARLIER('Table'[Date]) && 'Table'[Date] >= EARLIER('Table'[Date]) - 42 && 'Table'[StatysCode] = "NORMAL TIME" &&'Table'[Employeenumber] = EARLIER('Table'[Employeenumber]))) <> 1, 1,0)2.Final output
Best Regards,
Wenbin Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.