Forum Discussion

Oomsen's avatar
Oomsen
Icon for Helper III rankHelper 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

February    6           335.000

                  7

 

Currently the value is only shown by month. I would like to see 337.500 in week 2, 3, 4 and 5.

The data is add from a custom excelsheet.  

 

  • 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

     

9 Replies

    • Oomsen's avatar
      Oomsen
      Icon for Helper III rankHelper III

      v-chuncz-msft 

      Thanks for your reaction. 

      Can you be a little more specific where i need to add this in the query editor. 

  • Mariusz's avatar
    Mariusz
    Icon for Community Champion rankCommunity Champion

    Hi Oomsen 

     

    Please see the below creenshot

     

    Best Regards,
    Mariusz

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

    Please feel free to connect with me.
    Mariusz Repczynski

     

      • Mariusz's avatar
        Mariusz
        Icon for Community Champion rankCommunity Champion

        Hi Oomsen 

        Is there a reason why?

         

        Best Regards,
        Mariusz

        Please feel free to connect with me.
        Mariusz Repczynski