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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
cyy0296
New Member

find the 1st break, 2nd break, and lunch from each date and each employee

 

hi I have a table as below:
I would like to create a column and find 1st break, 2nd break, and lunch.

cyy0296_1-1691081841103.png

 

  1. if an agent on the same day, the aux name is Break and Duration is larger than 600. the first break will be the Break1, the second break will be the Break2
  2. if an agent on the same day, the aux name is Lunch and Duration is larger than 1000, it will be Lunch.

How do I perform this in Power BI DAX? I try couple time but it didn't work.

 

 

first Break =
VAR EmployeeDateBreaks =
FILTER(
'Adherence and Deviation',
[Employee Name] = EARLIER([Employee Name]) &&
[Date] = EARLIER([Date]) &&
[Aux Name] = "Break" &&
[Duration] > 600
)
RETURN
IF(
COUNTROWS(EmployeeDateBreaks) > 0 &&
RANKX(EmployeeDateBreaks, [Aux Start], , ASC) = 1,
"Break1",
BLANK()
)
Test.B1.ACTUAL =
VAR CurrentDate = 'Adherence and Deviation'[Date]
VAR CurrentEmployee = 'Adherence and Deviation'[Employee Name]
VAR FilteredTable = FILTER('Adherence and Deviation',[Date] = CurrentDate && [Employee Name] = CurrentEmployee &&
[Aux Name] = "break" &&
[Duration] >= 600)
VAR SecondBreakRow = ADDCOLUMNS ( FilteredTable, "Rank",
RANKX(FILTER('Adherence and Deviation', [Date] = CurrentDate &&
[Employee Name] = CurrentEmployee &&
[Aux Name] = "break" &&
[Duration] >= 600), [Aux Start], , ASC, Dense) )
RETURN IF ( NOT ISEMPTY(FilteredTable), MINX(FILTER(SecondBreakRow, [Rank] = 1), [Aux Start]), BLANK() )

 

 

data table 

 

 

thanks

1 ACCEPTED SOLUTION
ERD
Community Champion
Community Champion

Hi @cyy0296 ,

You were somewhat close. Please, try this code for your calculated column:

Column = 
VAR employee = Table_[Employee Name]
VAR day = Table_[Date]
VAR aux = Table_[Aux Name]
VAR duration = Table_[Duration]
VAR rnk =
    RANKX (
        FILTER (
            Table_,
            Table_[Employee Name] = employee
                && Table_[Duration] > 600
                && Table_[Date] = day
                && Table_[Aux Name] = "Break"
        ),
        Table_[Aux Start],
        ,
        ASC
    )
RETURN
    SWITCH (
        TRUE (),
        aux = "Lunch" && duration > 1000, "Lunch",
        aux = "Break" && Table_[Duration] > 600, CONCATENATE ( "Break ", rnk ),
        BLANK ()
    )

ERD_0-1691089719022.png

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

2 REPLIES 2
ERD
Community Champion
Community Champion

Hi @cyy0296 ,

You were somewhat close. Please, try this code for your calculated column:

Column = 
VAR employee = Table_[Employee Name]
VAR day = Table_[Date]
VAR aux = Table_[Aux Name]
VAR duration = Table_[Duration]
VAR rnk =
    RANKX (
        FILTER (
            Table_,
            Table_[Employee Name] = employee
                && Table_[Duration] > 600
                && Table_[Date] = day
                && Table_[Aux Name] = "Break"
        ),
        Table_[Aux Start],
        ,
        ASC
    )
RETURN
    SWITCH (
        TRUE (),
        aux = "Lunch" && duration > 1000, "Lunch",
        aux = "Break" && Table_[Duration] > 600, CONCATENATE ( "Break ", rnk ),
        BLANK ()
    )

ERD_0-1691089719022.png

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

this is crazy helpful. I learn a lot, thanks. @ERD 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.