Forum Discussion

MelQuick's avatar
MelQuick
New Member
5 years ago
Solved

Summarizing Hours in Date Columns

Hi - I have the table below which shows hours forecasted by week. What is the most efficient way to summarize that data in BI by month? Do I have to manually create a column for every month and add the weeks or is there an easier way to do that (I have over 5 years of data). Thanks!

 

 

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi MelQuick ,

     

    Our data sources are not the same. So just copy and add this part of M logic to Advanced Editor dialog:

    Or follow this:

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi MelQuick ,

     

    Our data sources are not the same. So just copy and add this part of M logic to Advanced Editor dialog:

    Or follow this:

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • MelQuick you should unpivot your data in power query

     

    - transform data
    - select the first two columns in your table
    - right-click, unpivot other columns it will add two columns, attribute, and value, rename these as per your requirement
    - close and apply

    To visualize,
    - matrix visual:
    - add an attribute on rows,
    - add value on values section

    Although if you want to work with date, it is recommended to add a date dimension and check my blog on how to add one.

     

    Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi MelQuick ,

     

    As parry2k suggested, please firstly transformed your table.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZFbCgMhDEX34ve05GF8LKLQ/8H9b6MmIthicRwwB1Hu9Saep3u/HoDucCBSiRnhqRuoJbgLcOUYLANXelSvUCtdrtGFqOchr3YwgSzQ/TQPRpPoQ+s1CiE3Oft2OU2ywlcSjkryeT8LKimGdmcj2kX303YQgtF606goN9AdSU0oWXNXWvuVskkzp3HQ8u/f52elfAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"WBS/CTR" = _t, PAAF = _t, #"12/31/20" = _t, #"01/01/21" = _t, #"01/08/21" = _t, #"01/15/21" = _t, #"01/22/21" = _t, #"01/29/21" = _t, #"02/05/21" = _t, #"02/12/21" = _t, #"02/19/21" = _t, #"02/26/21" = _t, #"03/05/21" = _t, #"03/12/21" = _t, #"03/19/21" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"WBS/CTR", type text}, {"PAAF", Int64.Type}, {"12/31/20", type number}, {"01/01/21", Int64.Type}, {"01/08/21", Int64.Type}, {"01/15/21", Int64.Type}, {"01/22/21", Int64.Type}, {"01/29/21", Int64.Type}, {"02/05/21", Int64.Type}, {"02/12/21", Int64.Type}, {"02/19/21", Int64.Type}, {"02/26/21", Int64.Type}, {"03/05/21", Int64.Type}, {"03/12/21", Int64.Type}, {"03/19/21", Int64.Type}}),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"WBS/CTR", "PAAF"}, "Attribute", "Value"),
        #"Changed Type1" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Attribute", type date}, {"Value", type number}})
    in
        #"Changed Type1"

    And use the following formula to add column

    YearMonth = FORMAT([Attribute],"YYYY-MM") 

    Then you could calculate the sum and create visuals:

    Measure =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            'Table',
            'Table'[WBS/CTR] = MAX ( 'Table'[WBS/CTR] )
                && 'Table'[YearMonth] = MAX ( 'Table'[YearMonth] )
        )
    )

    The final output is shown below:

     

    Please take a look at the pbix file here.


    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • MelQuick's avatar
      MelQuick
      New Member

      Hi Anonymous,

      Thanks for your reply and help!

      I pasted the above assuming ""nZFbCgMh..." was the sheet name but get the error 'Expression.SyntaxError: Token Comma Expected in 2 places:

      • #"07/30/21" = _t]),
      • in #"Changed Type1" (at the very end)

      Any ideas?

       

      Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Sheet1", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"WBS/CTR" = _t, PAAF = _t, #"12/31/20" = _t, #"01/01/21" = _t, #"01/08/21" = _t, #"01/15/21" = _t, #"01/22/21" = _t, #"01/29/21" = _t, #"02/05/21" = _t, #"02/12/21" = _t, #"02/19/21" = _t, #"02/26/21" = _t, #"03/05/21" = _t, #"03/12/21" = _t, #"03/19/21" = _t], #"03/26/20" = _t, #"04/02/21" = _t, #"04/09/21" = _t, #"04/16/21" = _t, #"04/23/21" = _t, #"04/30/21" = _t, #"05/07/21" = _t, #"05/14/21" = _t, #"05/21/21" = _t, #"05/28/21" = _t, #"06/04/21" = _t, #"06/11/21" = _t, #"06/18/21" = _t, #"06/25/21" = _t, #"07/02/21" = _t, #"07/09/21" = _t, #"07/16/21" = _t, #"07/23/21" #"07/30/21" = _t]),
      #"Changed Type" = Table.TransformColumnTypes(Source,{{"WBS/CTR", type text}, {"PAAF", Int64.Type}, {"12/31/20", type number}, {"01/01/21", Int64.Type}, {"01/08/21", Int64.Type}, {"01/15/21", Int64.Type}, {"01/22/21", Int64.Type}, {"01/29/21", Int64.Type}, {"02/05/21", Int64.Type}, {"02/12/21", Int64.Type}, {"02/19/21", Int64.Type}, {"02/26/21", Int64.Type}, {"03/05/21", Int64.Type}, {"03/12/21", Int64.Type}, {"03/19/21", {"03/26/21", Int64.Type}, {"04/02/21", Int64.Type}, {"04/09/21", Int64.Type}, {"04/16/21", Int64.Type}, {"04/23/21", Int64.Type}, {"04/30/21", Int64.Type}, {"05/07/21", Int64.Type}, {"05/14/21", Int64.Type}, {"05/21/21", Int64.Type}, {"05/28/21", Int64.Type}, {"06/04/21", Int64.Type}, {"06/11/21", Int64.Type}, {"06/18/21", Int64.Type}, {"06/25/21", Int64.Type}, {"07/02/21", Int64.Type}, {"07/09/21", Int64.Type}, {"07/16/21", Int64.Type}, {"07/23/21", Int64.Type}, {"07/30/21", Int64.Type}}), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"WBS/CTR", "PAAF"}, "Attribute", "Value"), #"Changed Type1" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Attribute", type date}, {"Value", type number}}) in #"Changed Type1"