cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
radissoufan Regular Visitor
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
Microsoft v-ljerr-msft
Microsoft

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

Hi @radissoufan,

 

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"
    )

c1.PNG

 

Here is the sample pbix file for your reference. Smiley Happy

 

Regards

View solution in original post

1 REPLY 1
Microsoft v-ljerr-msft
Microsoft

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

Hi @radissoufan,

 

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"
    )

c1.PNG

 

Here is the sample pbix file for your reference. Smiley Happy

 

Regards

View solution in original post

Helpful resources

Announcements
Coming Soon: T-Shirt Design Contest

Coming Soon: T-Shirt Design Contest

Keep your eyes open for our upcoming T-shirt design contest!

Meet the 2020 Season 1 Power BI Super Users!

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?

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 Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors
Top Kudoed Authors