cancel
Showing results for
Did you mean:
radissoufan Regular Visitor

## Dax formula to find odd Status records in a column

Hello..

I have a finger print system..

I have 2 devices one out the door and one inside the door

if an employee want to finger print when he is out in the inside device then he must finger print when he is back in the out device

if we said the ideal case will be

Emp Name           Mode                        Device          Time

A                Start\End of work Day         Out           1/1/2017 8:30 AM

B                Start\End of work Day         Out           1/1/2017 8:35 AM

A                         Break                           IN            1/1/2017 2:00 PM

A                         Break                          Out           1/1/2017 3:00 PM

A                Start\End of work Day          IN          1/1/2017 5:30 PM

B                Start\End of work Day          IN          1/1/2017 5:35 PM

I want to find cases that are a special case.. let's assume employee B finger print for a break when he is out but he forgat to finger print it when he back again and also Employee A finger print a wrong mode when he is  back of the break

Emp Name           Mode                        Device          Time

A                Start\End of work Day         Out           1/1/2017 8:30 AM

B                Start\End of work Day         Out           1/1/2017 8:35 AM

A                        Break                            IN            1/1/2017 2:00 PM

B                        Break                           IN            1/1/2017 2:00 PM

A                Start\End of work Day     Out           1/1/2017 3:00 PM

A                Start\End of work Day          IN            1/1/2017 5:30 PM

B                Start\End of work Day          IN             1/1/2017 5:35 PM

how can I find in DAX those cases... ?

1 ACCEPTED SOLUTION

Accepted Solutions v-ljerr-msft
Microsoft

## Re: Dax formula to find odd Status records in a column

It could be done with DAX in Power BI.

1. Use the formula below to add an Index column in your table.

```Index =
VAR currentTime = Table1[Time]
RETURN
CALCULATE (
RANK.EQ ( currentTime, Table1[Time], ASC ),
FILTER (
ALL ( Table1 ),
Table1[Emp Name] = EARLIER ( Table1[Emp Name] )
&& DATEVALUE ( Table1[Time] ) = DATEVALUE ( EARLIER ( Table1[Time] ) )
)
)```

2. Then you should be able to use the formula below to add another calculate column to flag the odd status.

```Status =
VAR nextMode =
CALCULATE (
FIRSTNONBLANK ( Table1[Mode], 1 ),
FILTER (
ALL ( Table1 ),
Table1[Emp Name] = EARLIER ( Table1[Emp Name] )
&& Table1[Index]
= EARLIER ( Table1[Index] ) + 1
)
)
VAR nextDevice =
CALCULATE (
FIRSTNONBLANK ( Table1[Device], 1 ),
FILTER (
ALL ( Table1 ),
Table1[Emp Name] = EARLIER ( Table1[Emp Name] )
&& Table1[Index]
= EARLIER ( Table1[Index] ) + 1
)
)
VAR preMode =
CALCULATE (
FIRSTNONBLANK ( Table1[Mode], 1 ),
FILTER (
ALL ( Table1 ),
Table1[Emp Name] = EARLIER ( Table1[Emp Name] )
&& Table1[Index]
= EARLIER ( Table1[Index] ) - 1
)
)
VAR preDevice =
CALCULATE (
FIRSTNONBLANK ( Table1[Device], 1 ),
FILTER (
ALL ( Table1 ),
Table1[Emp Name] = EARLIER ( Table1[Emp Name] )
&& Table1[Index]
= EARLIER ( Table1[Index] ) - 1
)
)
RETURN
IF (
( ( Table1[Mode] = "Break"
&& Table1[Device] = "IN" )
&& nextDevice = "IN" )
|| ( ( preMode = "Break"
&& preDevice = "IN" )
&& ( Table1[Mode] <> "Break"
&& Table1[Device] = "OUT" ) ),
"ODD"
)
``` Here is the sample pbix file for your reference. Regards v-ljerr-msft
Microsoft

## Re: Dax formula to find odd Status records in a column

It could be done with DAX in Power BI.

1. Use the formula below to add an Index column in your table.

```Index =
VAR currentTime = Table1[Time]
RETURN
CALCULATE (
RANK.EQ ( currentTime, Table1[Time], ASC ),
FILTER (
ALL ( Table1 ),
Table1[Emp Name] = EARLIER ( Table1[Emp Name] )
&& DATEVALUE ( Table1[Time] ) = DATEVALUE ( EARLIER ( Table1[Time] ) )
)
)```

2. Then you should be able to use the formula below to add another calculate column to flag the odd status.

```Status =
VAR nextMode =
CALCULATE (
FIRSTNONBLANK ( Table1[Mode], 1 ),
FILTER (
ALL ( Table1 ),
Table1[Emp Name] = EARLIER ( Table1[Emp Name] )
&& Table1[Index]
= EARLIER ( Table1[Index] ) + 1
)
)
VAR nextDevice =
CALCULATE (
FIRSTNONBLANK ( Table1[Device], 1 ),
FILTER (
ALL ( Table1 ),
Table1[Emp Name] = EARLIER ( Table1[Emp Name] )
&& Table1[Index]
= EARLIER ( Table1[Index] ) + 1
)
)
VAR preMode =
CALCULATE (
FIRSTNONBLANK ( Table1[Mode], 1 ),
FILTER (
ALL ( Table1 ),
Table1[Emp Name] = EARLIER ( Table1[Emp Name] )
&& Table1[Index]
= EARLIER ( Table1[Index] ) - 1
)
)
VAR preDevice =
CALCULATE (
FIRSTNONBLANK ( Table1[Device], 1 ),
FILTER (
ALL ( Table1 ),
Table1[Emp Name] = EARLIER ( Table1[Emp Name] )
&& Table1[Index]
= EARLIER ( Table1[Index] ) - 1
)
)
RETURN
IF (
( ( Table1[Mode] = "Break"
&& Table1[Device] = "IN" )
&& nextDevice = "IN" )
|| ( ( preMode = "Break"
&& preDevice = "IN" )
&& ( Table1[Mode] <> "Break"
&& Table1[Device] = "OUT" ) ),
"ODD"
)
``` Here is the sample pbix file for your reference. Regards

Announcements #### Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system. #### Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge. #### Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests! #### Power Platform Online Conference 