Forum Discussion

aTChris's avatar
aTChris
Icon for Resolver I rankResolver I
6 years ago
Solved

Function to calculate per week

Hi everyone, I hope you are all well.   I have an amazing function created by Mariusz . It calculates a monthly pro rated amount that I apply to a monthly revenue value. I then visualize that amoun...
  • Mariusz's avatar
    6 years ago

    Hi aTChris 

     

    Try this

    ( startDate as date, endDate as date ) => let
        dates = List.Dates( startDate, Duration.Days( endDate - startDate) + 1, #duration( 1, 0, 0, 0 ) ),
        transform = List.Transform( dates, each { _, ( Date.Year( _ ) * 100 ) + Date.WeekOfYear( _ ) } ),
        tableFrom = #table( type table [date= date, yearWeek = number ], transform ),
        group = Table.Group( tableFrom, {"yearWeek"}, {{"pct", each Table.RowCount(_) / 7, type number}}) 
    in  group

     

    Best Regards,
    Mariusz

    If this post helps, then please consider Accepting it as the solution.

    Please feel free to connect with me.
    LinkedIn