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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Cenex_Chris
New Member

Combining data from two columns with different dates

I am relatively new to PowerBI, so apologies if there is a simple solution I'm missing here. I have weekly timesheets created in a canvas app within Project for the Web. Each timesheet has a start date, then the number of hours per project per day (using just "Mon", "Tue", "Wed" etc.)

 

I'm trying to create monthly summaries of the data, but this is challenging because a week might start in one month and end in another. I've managed to set up columns to calculate what falls where, but it means that I basically have columns as follows:

 

PersonProjectMonth 1Month 1 HoursMonth 2

Month 2 hours

Person AProject 1Jan-2415Feb-245
Person AProject 2Jan-243Feb-240
Person AProject 3Feb-2410Mar-241
Person BProject 2Jan-2430Feb-240
Person CProject 1Feb-2421Mar-247
Person CProject 3Jan-245Feb-242
Person CProject 4Feb-241Mar-243

 

I want to consolidate the hours across the months, but without losing the person & project breakdown. In other words, I want to see the total hours booked to a project within a month by each individual.

Any suggestions of how I can do this?

 

I've tried a few different approaches, but I'm quite new to PowerBI and this has got me stumped. If I use the Month as the X-axis on a graph and then Month 1 hours and Month 2 hours as the Y-axis then I end up with Month 2 hours being associated to Month 1, which isn't right (e.g. for row 1 above, this would give 20 in Jan, rather than 15 hours in Jan and 5 in Feb.

 

Any help or suggestions would be amazing! Thanks 🙂

1 ACCEPTED SOLUTION
v-junyant-msft
Community Support
Community Support

Hi @Cenex_Chris ,

Your Month1 and Month2 are distributed in two columns, which is inconvenient when you create visual objects. Since this is the Power Query forum, I suggest you use the following M code in Power Query to transform your data:

vjunyantmsft_0-1721699979429.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgtKs7PU3BU0lEKKMrPSk0uUTAEsr0S83SNTIAMQ1Mg4ZaaBOGZKsXqYNVjhKzHGFmLAS4tKKoMDYCEb2IRlIesxwmnNQY47XFG8w5clZEhsj3muPQYI9uDEgJGuLSYoHgH2RZjpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Person = _t, Project = _t, #"Month 1" = _t, #"Month 1 Hours" = _t, #"Month 2" = _t, #"Month 2 hours" = _t]),
    #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Month 1", type date}, {"Month 2", type date}}, "en-GB"),
    #"Changed Type" = Table.TransformColumnTypes(#"Changed Type with Locale",{{"Month 1 Hours", Int64.Type}, {"Month 2 hours", Int64.Type}}),
    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Changed Type", {{"Month 1", type text}, {"Month 1 Hours", type text}}, "en-US"),{"Month 1", "Month 1 Hours"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
    #"Merged Columns1" = Table.CombineColumns(Table.TransformColumnTypes(#"Merged Columns", {{"Month 2", type text}, {"Month 2 hours", type text}}, "en-US"),{"Month 2", "Month 2 hours"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged.1"),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Merged Columns1", {"Person", "Project"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Value", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Value.1", "Value.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Value.1", type date}, {"Value.2", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Attribute"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Value.1", "Month"}, {"Value.2", "Value"}})
in
    #"Renamed Columns"

Just create a blank query and put all of the function into the Advanced Editor:

vjunyantmsft_1-1721700068784.png

vjunyantmsft_2-1721700079559.png

 

vjunyantmsft_3-1721700089938.png

And after transformation:

vjunyantmsft_4-1721700121014.png

Then click "Close and Apply":

vjunyantmsft_5-1721700144195.png

Then you can create the visual, here I will give you an example:

vjunyantmsft_6-1721700448711.png

Or like this:

vjunyantmsft_7-1721700465670.png


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

View solution in original post

1 REPLY 1
v-junyant-msft
Community Support
Community Support

Hi @Cenex_Chris ,

Your Month1 and Month2 are distributed in two columns, which is inconvenient when you create visual objects. Since this is the Power Query forum, I suggest you use the following M code in Power Query to transform your data:

vjunyantmsft_0-1721699979429.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgtKs7PU3BU0lEKKMrPSk0uUTAEsr0S83SNTIAMQ1Mg4ZaaBOGZKsXqYNVjhKzHGFmLAS4tKKoMDYCEb2IRlIesxwmnNQY47XFG8w5clZEhsj3muPQYI9uDEgJGuLSYoHgH2RZjpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Person = _t, Project = _t, #"Month 1" = _t, #"Month 1 Hours" = _t, #"Month 2" = _t, #"Month 2 hours" = _t]),
    #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Month 1", type date}, {"Month 2", type date}}, "en-GB"),
    #"Changed Type" = Table.TransformColumnTypes(#"Changed Type with Locale",{{"Month 1 Hours", Int64.Type}, {"Month 2 hours", Int64.Type}}),
    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Changed Type", {{"Month 1", type text}, {"Month 1 Hours", type text}}, "en-US"),{"Month 1", "Month 1 Hours"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
    #"Merged Columns1" = Table.CombineColumns(Table.TransformColumnTypes(#"Merged Columns", {{"Month 2", type text}, {"Month 2 hours", type text}}, "en-US"),{"Month 2", "Month 2 hours"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged.1"),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Merged Columns1", {"Person", "Project"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Value", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Value.1", "Value.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Value.1", type date}, {"Value.2", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Attribute"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Value.1", "Month"}, {"Value.2", "Value"}})
in
    #"Renamed Columns"

Just create a blank query and put all of the function into the Advanced Editor:

vjunyantmsft_1-1721700068784.png

vjunyantmsft_2-1721700079559.png

 

vjunyantmsft_3-1721700089938.png

And after transformation:

vjunyantmsft_4-1721700121014.png

Then click "Close and Apply":

vjunyantmsft_5-1721700144195.png

Then you can create the visual, here I will give you an example:

vjunyantmsft_6-1721700448711.png

Or like this:

vjunyantmsft_7-1721700465670.png


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

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors