Forum Discussion
raicardi
4 years agoFrequent Visitor
Calculate overlapping shift start
I am relatively new to BI, more used to excel, and am having a difficult time showing overlapping shift. Formula and screenshot of excel below. F(F3=F2, IF(H3=I2, "follow", IF(H3<I2, "OVERLAP", "Af...
- 4 years ago
Hi raicardi ,
Approve with MahyarTF .
Here is my solution:
You can create index column in Power Query:
Here is the M code:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJS0lEytLC01DU00jU2UDAwtzIwACJUUUNTqGisDi6NhsZWxpgajQyhohCNRuTaiE0jUTYak2sjNo2EbIwFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Work Date" = _t, #"In Time" = _t, #"Out Time" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Work Date", type date}, {"In Time", type datetime}, {"Out Time", type datetime}}), #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type) in #"Added Index"Then create and apply the measure:
Measure = var _a = MAX('Table'[Index]) var _b = FILTER(ALL('Table'),[Index]=_a-1) return IF( MAXX(_b,'Table'[Work Date])=MAX('Table'[Work Date]), SWITCH(TRUE(), MAXX(_b,[Out Time])=MAX('Table'[In Time]),"follow", MAXX(_b,[Out Time])>MAX('Table'[In Time]),"OVERLAP", "After"),"---")Output:
Kind Regards,
Bubble
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
MahyarTF
4 years agoMemorable Member
Hi,
- I create the column as an Index Column :
DAX Index =
RANKX(
ALL( Sheet72 ), --Table Name
CONCATENATE( Sheet72[Word Day], format( Sheet72[In Time], "hh:mm:ss") ),,
ASC,
Dense
)
- then create another Column to calculate the particular column :
Previous Quantity =
VAR _CurrentRowIndex = Sheet72[DAX Index]
VAR _PreviousRowDate = CALCULATE(format(MAX( Sheet72[Word Day]), "dd/mm/yyy") ,
FILTER( Sheet72, Sheet72[DAX Index] < _CurrentRowIndex ),
ALL( Sheet72[DAX Index] ) )
Var _CurrentRowDate = format (CALCULATE( max(Sheet72[Word Day])), "dd/mm/yyy")
/*VAR _PreviousRowInTime = CALCULATE(format(MAX( Sheet72[In Time]), "hh:mm:ss") , FILTER( Sheet72, Sheet72[DAX Index] < _CurrentRowIndex ), ALL( Sheet72[DAX Index] ) ) */
Var _CurrentRowInTime = format (CALCULATE( max(Sheet72[In Time])), "hh:mm:ss")
VAR _PreviousRowOutTime = CALCULATE(format(MAX( Sheet72[Out Time]), "hh:mm:ss") ,
FILTER( Sheet72, Sheet72[DAX Index] = _CurrentRowIndex-1 ),
ALL( Sheet72[DAX Index] ) )
--Var _CurrentRowOutTime = format (CALCULATE( max(Sheet72[Out Time])), "hh:mm:ss")
Var _result = if(_PreviousRowDate = _CurrentRowDate,
if(_CurrentRowInTime = _PreviousRowOutTime, "follow",
if(_CurrentRowInTime < _PreviousRowOutTime, "OVERLAP", "After")
)
,"---"
)
RETURN
_Result
- Now this is the result Table visual :
raicardi
4 years agoFrequent Visitor
Thanks for the infomation. I realized i needed to group 20 distinct locations so the formula above was helpful but am stil unable to achieve the result im looing for. Columns and screenshots below. [DAX Index] below is the
Overlap = VAR _CurrentRowIndex = Sheet1[DAX Index]
VAR _PreviousRowDate = CALCULATE(format(MAX( Sheet1[Work Date]), "dd/mm/yyy") ,
FILTER( Sheet1, Sheet1[DAX Index] < _CurrentRowIndex ),
ALL( Sheet1[DAX Index] ) )
Var _CurrentRowDate = format (CALCULATE( max(Sheet1[Work Date])), "dd/mm/yyy")
/*VAR _PreviousRowInTime = CALCULATE(format(MAX( Sheet1[In Time]), "hh:mm:ss") , FILTER( Sheet1, Sheet1[DAX Index] < _CurrentRowIndex ), ALL( Sheet1[DAX Index] ) ) */
Var _CurrentRowInTime = format (CALCULATE( max(Sheet1[In Time])), "hh:mm:ss")
VAR _PreviousRowOutTime = CALCULATE(format(MAX( Sheet1[Out Time]), "hh:mm:ss") ,
FILTER( Sheet1, Sheet1[DAX Index] = _CurrentRowIndex-1 ),
ALL( Sheet1[DAX Index] ) )
--Var _CurrentRowOutTime = format (CALCULATE( max(Sheet1[Out Time])), "hh:mm:ss")
Var _result = if(_PreviousRowDate = _CurrentRowDate,
if(_CurrentRowInTime >= _PreviousRowOutTime, "follow",
if(_CurrentRowInTime <= _PreviousRowOutTime, "OVERLAP", "After")
)
,"---"
)
RETURN
_Result
Results below are after group by indexes added for each of the 20 groups.
- MahyarTF4 years agoMemorable Member
Not sure, why it is not working,
Would you please share your sample PBIX file ?
I check my doing again and it is working
- raicardi4 years agoFrequent Visitor
Let me know if this works?
Work Date In Time Out Time Overlap Order 1/1/2022 1899-12-30 07:00:00 1899-12-30 15:00:00 '--- 1 1/1/2022 1899-12-30 13:30:00 1899-12-30 21:30:00 '--- 2 1/2/2022 1899-12-30 07:00:00 1899-12-30 15:00:00 '--- 3 1/2/2022 1899-12-30 13:30:00 1899-12-30 21:30:00 '--- 4 1/3/2022 1899-12-30 07:00:00 1899-12-30 15:00:00 '--- 5 1/3/2022 1899-12-30 13:30:00 1899-12-30 21:30:00 '--- 6 1/4/2022 1899-12-30 07:00:00 1899-12-30 21:30:00 '--- 7 1/5/2022 1899-12-30 07:00:00 1899-12-30 21:30:00 '--- 8 1/6/2022 1899-12-30 07:00:00 1899-12-30 21:30:00 '--- 9 1/7/2022 1899-12-30 07:00:00 1899-12-30 15:00:00 '--- 10 1/7/2022 1899-12-30 13:30:00 1899-12-30 21:30:00 '--- 11 1/8/2022 1899-12-30 07:00:00 1899-12-30 21:30:00 '--- 12 1/9/2022 1899-12-30 07:00:00 1899-12-30 15:00:00 OVERLAP 13 1/9/2022 1899-12-30 13:30:00 1899-12-30 21:30:00 OVERLAP 14 ######## 1899-12-30 07:00:00 1899-12-30 15:00:00 '--- 15 ######## 1899-12-30 13:30:00 1899-12-30 21:30:00 '--- 16 ######## 1899-12-30 07:00:00 1899-12-30 21:30:00 '--- 17 ######## 1899-12-30 07:00:00 1899-12-30 15:00:00 '--- 18 ######## 1899-12-30 13:30:00 1899-12-30 21:30:00 '--- 19 ######## 1899-12-30 07:00:00 1899-12-30 15:00:00 '--- 20 ######## 1899-12-30 13:30:00 1899-12-30 21:30:00 '--- 21 ######## 1899-12-30 07:00:00 1899-12-30 21:30:00 '--- 22 ######## 1899-12-30 07:00:00 1899-12-30 15:00:00 '--- 23 ######## 1899-12-30 13:30:00 1899-12-30 21:30:00 '--- 24 ######## 1899-12-30 07:00:00 1899-12-30 21:30:00 '--- 25 ######## 1899-12-30 07:00:00 1899-12-30 15:00:00 '--- 26 ######## 1899-12-30 13:30:00 1899-12-30 21:30:00 '--- 27 ######## 1899-12-30 07:00:00 1899-12-30 21:30:00 '--- 28 ######## 1899-12-30 07:00:00 1899-12-30 15:00:00 '--- 29 ######## 1899-12-30 13:30:00 1899-12-30 21:30:00 '--- 30 ######## 1899-12-30 07:00:00 1899-12-30 21:30:00 '--- 31 ######## 1899-12-30 07:00:00 1899-12-30 15:00:00 '--- 32 ######## 1899-12-30 13:30:00 1899-12-30 21:30:00 '--- 33 ######## 1899-12-30 07:00:00 1899-12-30 21:30:00 '--- 34 ######## 1899-12-30 07:00:00 1899-12-30 21:30:00 '--- 35 ######## 1899-12-30 07:00:00 1899-12-30 15:00:00 '--- 36 ######## 1899-12-30 13:30:00 1899-12-30 21:30:00 '--- 37 ######## 1899-12-30 07:00:00 1899-12-30 21:30:00 '--- 38 ######## 1899-12-30 07:00:00 1899-12-30 21:30:00 '--- 39 ######## 1899-12-30 07:00:00 1899-12-30 21:30:00 '--- 40 ######## 1899-12-30 07:00:00 1899-12-30 15:00:00 '--- 41 ######## 1899-12-30 13:30:00 1899-12-30 21:30:00 '--- 42 ######## 1899-12-30 07:00:00 1899-12-30 15:00:00 '--- 43 ######## 1899-12-30 13:30:00 1899-12-30 21:30:00 '--- 44 ######## 1899-12-30 07:00:00 1899-12-30 21:30:00 '--- 45 ######## 1899-12-30 15:00:00 1899-12-30 21:30:00 '--- 46 ######## 1899-12-30 07:00:00 1899-12-30 15:00:00 '--- 47 - MahyarTF4 years agoMemorable Member
Hi,
This is my result :