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
Gedmonston
Frequent Visitor

showing consecutive days worked

Hi, 

 

I have a data set that contains columns for the amount of hours worked each day of the month like so:

This data also contains a payroll codes for absent staff.

D1 D2 D3 etc

8   10  OF

 

 

is there a way to show the maximum number of consecutive days worked?

 

 

 

Any help would be greatly apprieciated

1 ACCEPTED SOLUTION
v-lid-msft
Community Support
Community Support

Hi @Gedmonston ,

 

We can create a measure using following formula to meet your requirement:

 

 

MaxWorkDay = 
MAXX (
    ADDCOLUMNS (
        FILTER ( 'Table', 'Table'[Payroll] = "OF" ),
        "WorkDay",
        VAR tday = [Date]
        RETURN
            VAR diff =
                DATEDIFF (
                    MAXX (
                        FILTER ( FILTER ( 'Table', 'Table'[Payroll] = "OF" ), [Date] < tday ),
                        [Date]
                    ),
                    tday,
                    DAY
                )
            RETURN
                IF (
                    diff = BLANK (),
                    COUNTROWS ( FILTER ( 'Table', [Date] < tday ) ),
                    diff - 1
                )
    ),
    [WorkDay]
)

 

 

5.PNG


If it doesn't meet your requirement, kindly share your sample data and expected result to me if you don't have any Confidential Information. Please upload your files to One Drive and share the link here.


BTW, pbix as attached.

 

Best regards,

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Dong Li
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

2 REPLIES 2
v-lid-msft
Community Support
Community Support

Hi @Gedmonston ,

 

We can create a measure using following formula to meet your requirement:

 

 

MaxWorkDay = 
MAXX (
    ADDCOLUMNS (
        FILTER ( 'Table', 'Table'[Payroll] = "OF" ),
        "WorkDay",
        VAR tday = [Date]
        RETURN
            VAR diff =
                DATEDIFF (
                    MAXX (
                        FILTER ( FILTER ( 'Table', 'Table'[Payroll] = "OF" ), [Date] < tday ),
                        [Date]
                    ),
                    tday,
                    DAY
                )
            RETURN
                IF (
                    diff = BLANK (),
                    COUNTROWS ( FILTER ( 'Table', [Date] < tday ) ),
                    diff - 1
                )
    ),
    [WorkDay]
)

 

 

5.PNG


If it doesn't meet your requirement, kindly share your sample data and expected result to me if you don't have any Confidential Information. Please upload your files to One Drive and share the link here.


BTW, pbix as attached.

 

Best regards,

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
rheiasilvia
Advocate I
Advocate I

Hi @Gedmonston,

 

You need to create a new column in you Calendar table first. For do this in the Power Query Editor, click on you date column and click on the menu add column, bottom Date, go to item Day and choose day of the week . After that you shoud add a custom column, in this column you will type a formula that will help you to dived  the weekends for the work days, is something like this:

 

 if [day of the week]=6 then 0 else if [day of the week]=0 then 0 else 1

*I will named this column Weekends

 

In you table, which has all the days with the hours, you should split the column D1, D2 ... for use the days; And for the hour column you must change the word OF for 0. To do this in the  Power Query Editor, click on the bottom custom column e type the formula:

 

 if [Hours]="OF" then 0 else [Hours]

* I will name this formula HoursWorked

 

Next click on close and apply. In the Manage Relationships, make sure that your table has one relationship with the Calendar table. Then you can create a new measure for sum the hours, this formula will look only for the hours of the day of the week.

Is something like this :

 

CALCULATE(SUM(yorhourtable[HoursWorked]);FILTER(Calendar;Calendar[Weekends]=1)).
 
I hope it helped you

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.