Forum Discussion

Oomsen's avatar
Oomsen
Helper III
7 years ago
Solved

Monthly value by week

I would like to show a monthly value by week. Month      Week     Value January     1            337.500                   2                   3                   4                    5 Februa...
  • Mariusz's avatar
    Mariusz
    7 years ago

    Hi Oomsen 

    Please see the below M code, this will expand your months to weeks.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDUByIjA0MLJR2lQwsUYMjYzNzUwODQAqCoMUJJrA5EhxFWHUANEB1GFnAlMB3GWHUYIdsBVRIbCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t, Value = _t, #"End date" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Value", Int64.Type}, {"End date", type date}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Distinct( List.Transform( List.Dates( [Date],  Duration.Days( [End date] - [Date] ), #duration( 1, 0, 0, 0 ) ), each Date.WeekOfYear(_) ) )),
        #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
        #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Custom", type number}})
    in
        #"Changed Type1"
     
    Best Regards,
    Mariusz

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

    Please feel free to connect with me.
    Mariusz Repczynski