Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Raveen
Frequent Visitor

Count time entries as 1 one if is less than 25 minutes

Hello, i am struggling with getting unique count if centains rows falls winthin 25 min.

 

Request is to count unique actions based on multiple columns.

If Agent, Company, Type is the same and Time is less than 25 minutes from first entry it should not count.

 

AgentCompanyTypeDate + timeDateTimeCount as action
JohnRestaurant AAAIncident09/11/2020 09:2309/11/202009:23:001
JohnRestaurant AAAIncident09/11/2020 09:2309/11/202009:23:00 
JohnRestaurant AAAIncident09/11/2020 09:2409/11/202009:24:00 
JohnRestaurant AAAIncident09/11/2020 09:2409/11/202009:24:00 
KarenHotel AAAIncident09/11/2020 09:2509/11/202009:25:001
KarenHotel AAAIncident09/11/2020 09:2509/11/202009:25:00 
JohnCafé AAAIncident09/11/2020 09:2509/11/202009:25:001
JohnCafé AAAIncident09/11/2020 09:2609/11/202009:26:00 
JohnCafé AAAIncident09/11/2020 09:2609/11/202009:26:00 
JohnCafé AAAIncident09/11/2020 09:2809/11/202009:28:00 
JohnCafé AAAIssue09/11/2020 09:2809/11/202009:28:001
JohnRestaurant BBBIncident09/11/2020 09:2909/11/202009:29:001
JohnRestaurant BBBIncident09/11/2020 09:3009/11/202009:30:00 
JohnRestaurant BBBIncident09/11/2020 09:3209/11/202009:32:00 
JohnRestaurant BBBIncident09/11/2020 09:3309/11/202009:33:00 
JohnRestaurant BBBIssue09/11/2020 09:3409/11/202009:34:001
KarenHotel BBBIncident09/11/2020 09:3409/11/202009:34:001
KarenHotel BBBIncident09/11/2020 09:3509/11/202009:35:00 
KarenHotel BBBIncident09/11/2020 09:3609/11/202009:36:00 
KarenHotel BBBIncident09/11/2020 09:3609/11/202009:36:00 
JohnCafé AAAIncident09/11/2020 09:4009/11/202009:40:00 
JohnCafé AAAIncident09/11/2020 09:4009/11/202009:40:00 
JohnCafé AAAIncident09/11/2020 09:4009/11/202009:40:00 
JohnCafé AAAIncident09/11/2020 09:4109/11/202009:41:00 
JohnCafé AAAIncident09/11/2020 09:4109/11/202009:41:00 
JohnCafé AAAIncident09/11/2020 09:4109/11/202009:41:00 
JohnCafé AAAIncident09/11/2020 09:5109/11/202009:51:001

 

I am not sure how to start with the time column, if i could be pointed in the right direction please.

 

I did find some posts about time entries or time tables but i could not get them to work for my case.

1 ACCEPTED SOLUTION

Hi @Raveen  ,

 

You could modify “count as action” measure as follows:

count as action =
VAR _diff =
    DATEDIFF (
        CALCULATE (
            MIN ( [Date + time] ),
            ALLEXCEPT ( 'Table', 'Table'[Agent], 'Table'[Company], 'Table'[Type] )
        ),
        MAX ( [Date + time] ),
        MINUTE
    )
VAR _indexmin =
    CALCULATE (
        MIN ( [Index] ),
        ALLEXCEPT ( 'Table', 'Table'[Agent], 'Table'[Type], 'Table'[Company] )
    )
RETURN
    IF ( _diff > 25, 1, IF ( MAX ( [Index] ) = _indexmin, 1 ) )

The final output is shown below:

v-yalanwu-msft_0-1622014891117.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.  

View solution in original post

12 REPLIES 12
v-yalanwu-msft
Community Support
Community Support

Hi @Raveen  , 

 

You could create three measure as follows:

1.First Request ( create a measure to count unique actions)

count as action =
VAR _diff =
    DATEDIFF (
        CALCULATE (
            MIN ( [Date + time] ),
            ALLEXCEPT ( 'Table', 'Table'[Agent], 'Table'[Company], 'Table'[Type] )),
        MAX ( [Date + time] ),
        MINUTE)
VAR _indexmin =
    CALCULATE (
        MIN ( [Index] ),
        ALLEXCEPT ( 'Table', 'Table'[Agent], 'Table'[Type], 'Table'[Company] ))
RETURN
    IF ( _diff = 0 && MAX ( [Index] ) = _indexmin, 1 )

2.Second Request ( create a measure to sum count)

Measue1:

Flag =
VAR _diff =
    DATEDIFF (
        CALCULATE (
            MIN ( [Date + time] ),
            ALLEXCEPT ( 'Table', 'Table'[Agent], 'Table'[Company] )
        ),
        MAX ( [Date + time] ),
        MINUTE
    )
VAR _indexmin =
    CALCULATE (
        MIN ( [Index] ),
        ALLEXCEPT ( 'Table', 'Table'[Agent], 'Table'[Company] )
    )
RETURN
    IF ( _diff = 0 && MAX ( [Index] ) = _indexmin, 1 )

 Measue2:

sum =SUMX ( FILTER ( ALL ( 'Table' ), [Index] <= MAX ( [Index] ) ), [Flag] )

Measue3:

# Count =
MINX (
    FILTER (
        ALL ( 'Table' ),
        'Table'[Agent] = MAX ( 'Table'[Agent] )
            && 'Table'[Company] = MAX ( 'Table'[Company] )
            && 'Table'[Type] = MAX ( 'Table'[Type] )),
    [sum])

The final output is shown below:

v-yalanwu-msft_0-1621936656275.png

 

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yalanwu-msft 

This is almost what i need, just missing the "Count row if more than 25 minutes difference".

 

If you would add a new row(28) in the table:

Raveen_1-1621955590195.png

This one should be counted as new action.

If there are more rows with the same Agent, Company, Type and the time is 10:11:00 or more it should count as another action and so on for that day.

 

regards, raveen

Hi @Raveen  ,

 

You could modify “count as action” measure as follows:

count as action =
VAR _diff =
    DATEDIFF (
        CALCULATE (
            MIN ( [Date + time] ),
            ALLEXCEPT ( 'Table', 'Table'[Agent], 'Table'[Company], 'Table'[Type] )
        ),
        MAX ( [Date + time] ),
        MINUTE
    )
VAR _indexmin =
    CALCULATE (
        MIN ( [Index] ),
        ALLEXCEPT ( 'Table', 'Table'[Agent], 'Table'[Type], 'Table'[Company] )
    )
RETURN
    IF ( _diff > 25, 1, IF ( MAX ( [Index] ) = _indexmin, 1 ) )

The final output is shown below:

v-yalanwu-msft_0-1622014891117.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.  

@v-yalanwu-msft 

 

Need some time to check if it produces the correct result, wil update soon.

As a follow up, would it be possible to add the same columns in the data table?

Raveen_0-1622019177571.png

 

Hi, @Raveen ,

 

You can see my pbix file. I have changed the correct answer, but I don't know whether it matches your logic. If it's not the result you want, can you provide the picture of the result you want, or more details and logic.

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

Fowmy
Super User
Super User

@Raveen 

Need a bit more clarity on your explanation. Can you explain how you calculated values as one in "Count as Action" with examples? 


Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Raveen
Frequent Visitor

Sorry for the picture, keep getting errors when posting.

Raveen_0-1621762844866.png

 

Raveen
Frequent Visitor

Of course, every combination of colum A, B, C and G is counted as action.

Then if the colum G(Time) is more then 25 with the same combination.

 

when to count as action:

Action 1. Row 8 is the first action with "John"(A), "Cafe; AAA"(B) , "Incident"(C) and "09:25:00"(G).

Row 22 - 28 have the same combination as row 8 and the G(Time) is in the range of "09:25:00" + 25 minutes = 09:50:00, they are not counted.

 

Action 2. Row 12 colum C has different value "Issue" thus counted as a seperate action.

 

Action 3. Row 29 have the same combination as row 8 but the time"09:51:00"(G) is not in the range of "09:25:00" + 25 minutes = 09:50:00.

 

Does this help @Fowmy ?

Thank you for having a look.

@Raveen 

In your sample data, I don't see a column that is unique between entries, for example,  what is the difference between rows 2 and 3? How do I distinguish bettwen them?

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Raveen
Frequent Visitor

Data comes from a system where the user gets notification to perform a manual action.

Depending on the action type there could be one or multiple follow up actions to do.

Every action comes out as a seperate row in the daily data exports.

 

The requirement is when the user takes more thaan 25 minutes to handle the next action it schould be counted as a seperate action.

Of course this is only for the same Agent, Company and Type on that day.

 

@Fowmy 

Raveen
Frequent Visitor

@Fowmy 

There are additional columns like, Action type, sub-type and result for each row.

 

 

@Raveen 

 

Okay, I suggest you share a sample that exactly represent your actual data. 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.