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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
BDale93
Helper I
Helper I

Paid Time Off days listed from based on submission date and total hours

Hello,

I have a unique scenario where we pull data from a payroll platform to get PTO hours for employees. The data comes in on one line, ex below. Does anyone know of a way to if total hours is greater than 8, then create a new line for each instance of 8hrs untill the total for that singular line is met? Each new row would be the next day after the original submission date, and would need to skip weekends. Any assistance would be appreciated

Current Data Format: (Submission Date / Total Hours)
3/28/2024 | 40hrs

Desired Format: (Date / Total Hours)
3/28/2024 | 8hrs
3/29/2024 | 8hrs

4/1/2024   | 8hrs

4/2/2024   | 8hrs

4/3/2024   | 8hrs

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @BDale93, check this.

 

Result

dufoq3_0-1713207175595.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtY3stA3MjAyUahRMDHIKCpWio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    SplitColumnByDelimiter = Table.SplitColumn(Source, "Column1", Splitter.SplitTextByDelimiter(" | ", QuoteStyle.Csv), {"Date", "Total Hours"}),
    ExtractedTextBeforeDelimiter = Table.TransformColumns(SplitColumnByDelimiter, {{"Total Hours", each Number.From(Text.BeforeDelimiter(_, "hrs")), type number}}),
    ChangedType = Table.TransformColumnTypes(ExtractedTextBeforeDelimiter,{{"Date", type date}}, "en-US"),
    AddedCustom = Table.AddColumn(ChangedType, "Custom", each
        Table.FromRecords(List.Generate(
            ()=> [ d=[Date], x=[Total Hours], h=8 ],
            each [h] > 0,
            each [ d=List.First(List.Select(List.Dates(Date.AddDays([d],1), 3, #duration(1,0,0,0)), (z)=> Date.DayOfWeek(z) < 5)), x=[x]-8, h= if x >= 8 then 8 else x ],
            each [ Output = Date.ToText([d], [Format="M/d/yyyy", Culture="en-US"]) & " | " & Text.From([h]) & "hrs" ]
        )), type table),
    CombinedCustom = Table.Combine(AddedCustom[Custom])
in
    CombinedCustom

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

1 REPLY 1
dufoq3
Super User
Super User

Hi @BDale93, check this.

 

Result

dufoq3_0-1713207175595.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtY3stA3MjAyUahRMDHIKCpWio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    SplitColumnByDelimiter = Table.SplitColumn(Source, "Column1", Splitter.SplitTextByDelimiter(" | ", QuoteStyle.Csv), {"Date", "Total Hours"}),
    ExtractedTextBeforeDelimiter = Table.TransformColumns(SplitColumnByDelimiter, {{"Total Hours", each Number.From(Text.BeforeDelimiter(_, "hrs")), type number}}),
    ChangedType = Table.TransformColumnTypes(ExtractedTextBeforeDelimiter,{{"Date", type date}}, "en-US"),
    AddedCustom = Table.AddColumn(ChangedType, "Custom", each
        Table.FromRecords(List.Generate(
            ()=> [ d=[Date], x=[Total Hours], h=8 ],
            each [h] > 0,
            each [ d=List.First(List.Select(List.Dates(Date.AddDays([d],1), 3, #duration(1,0,0,0)), (z)=> Date.DayOfWeek(z) < 5)), x=[x]-8, h= if x >= 8 then 8 else x ],
            each [ Output = Date.ToText([d], [Format="M/d/yyyy", Culture="en-US"]) & " | " & Text.From([h]) & "hrs" ]
        )), type table),
    CombinedCustom = Table.Combine(AddedCustom[Custom])
in
    CombinedCustom

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors
Top Kudoed Authors