Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

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   ...
  • v-lid-msft's avatar
    6 years ago

    Hi Anonymous ,

     

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

     

     


    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.