Forum Discussion
Identify transactions in different rows in same table based on mulitple criteria
- 6 years ago
Sorry, the Excel document did not post for some reason. here is the same table as the picture in the post.
Employee Name OT Code Group Date Ot start time Ot end time Multiple people in same group doing Overtime type x at same time? Mr A X East 2019-01-01 8:00 10:00 Yes Mr B Z West 2019-01-01 12:00 14:00 No Mr C X East 2019-01-01 9:00 11:00 Yes Mr A Z West 2019-01-02 8:00 11:00 No Mr B Z West 2019-01-02 8:00 12:00 No Mr C Y West 2019-01-02 8:00 10:00 No Mr A X West 2019-01-03 12:00 14:00 Yes Mr B Y East 2019-01-03 9:00 11:00 No Mr C X West 2019-01-03 12:00 14:00 Yes
Sorry, the Excel document did not post for some reason. here is the same table as the picture in the post.
| Employee Name | OT Code | Group | Date | Ot start time | Ot end time | Multiple people in same group doing Overtime type x at same time? |
| Mr A | X | East | 2019-01-01 | 8:00 | 10:00 | Yes |
| Mr B | Z | West | 2019-01-01 | 12:00 | 14:00 | No |
| Mr C | X | East | 2019-01-01 | 9:00 | 11:00 | Yes |
| Mr A | Z | West | 2019-01-02 | 8:00 | 11:00 | No |
| Mr B | Z | West | 2019-01-02 | 8:00 | 12:00 | No |
| Mr C | Y | West | 2019-01-02 | 8:00 | 10:00 | No |
| Mr A | X | West | 2019-01-03 | 12:00 | 14:00 | Yes |
| Mr B | Y | East | 2019-01-03 | 9:00 | 11:00 | No |
| Mr C | X | West | 2019-01-03 | 12:00 | 14:00 | Yes |
OK LearnmesomePBI , this turned out to be WAAAAYYYYY more complex than I anticipated going into it. But I think I have a solution. PBIX is attached.
Column =
VAR __Table =
GROUPBY(
FILTER(
ALL('Table'),
[OT Code] = "X"
),
[Group],
[Date],
"__Min",MINX(CURRENTGROUP(),'Table'[Ot start time]),
"__Max",MAXX(CURRENTGROUP(),'Table'[Ot end time])
)
VAR __Min =
MINX(
FILTER(
__Table,
[Group] = EARLIER([Group]) &&
[Date] = EARLIER('Table'[Date])
),
[__Min]
)
VAR __Max =
MAXX(
FILTER(
__Table,
[Group] = EARLIER([Group]) &&
[Date] = EARLIER('Table'[Date])
),
[__Max]
)
VAR __Table1 =
ADDCOLUMNS(
'Table',
"__Count",
IF([Ot start time] >= __Min || [Ot end time] <= __Max,1,0)
)
VAR __Count =
SUMX(
FILTER(
__Table1,
[Group] = EARLIER([Group]) &&
[Date] = EARLIER([Date])
),
[__Count]
)
RETURN
IF([OT Code] <> "X","No",IF(__Count > 1,"Yes", "No"))
- LearnmesomePBI6 years agoFrequent Visitor
Sorry for my delay in responding. I have a fairly large file and wanted to "kick the tires" on your proposed solution and see if it was working as intended in all circumstances. Good news is that it works amazing.
I did run into a problem whereby some transaction lines spanned two calendar days. Ex. 2019-05-24 OT start at 23:00 and finished 01:15.
I ended up creating a bunch of conditional columns in the query editor and using the unpivot function to break the transaction out on two lines and then your calculation executed appropriately.
Thanks so much Greg for all of your help. Wicked solution!
- Greg_Deckler6 years agoCommunity ChampionNo problem LearnmesomePBI ! I actually thought about that scenario when I was developing the DAX code but wasn't up for addressing it at the time! That's a smart solution you found for that, likely way better than trying to account for it in DAX!