cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rjsidek Helper II
Helper II

Creating a Summary Table from an existing table

Hi everyone, I have a sample dataset that looks a bit like this

 

question 1.png

 

I want to create summary table that shows all the entries of a company in one single row. Ideally, I would have one row for each company. I tried to use summariza by max date, but certain entries won't be captured. For example, for company "a", if I summarized by max date, the only column that would have an entry is the status column and everything else would be empty. The final output table that I would want looks something like this:

 

Answer 1.png

 

Can I achieve this with PowerQuery? Any help is appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
rajulshah Solution Sage
Solution Sage

Re: Creating a Summary Table from an existing table

Hello @rjsidek,

 

Please try following M query code :

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hZBfC4IwFMW/iuw52N1MykfpD/QSgb1JD7YGDmyG0z5/904zTSi43N2xwzm/3SxjOVswkFxILkHEeDnp2lU2EDgKAOyS2rGqmyJInCH9pjDWn5V17V3XOCaqMU/NLoveMRo5diWjYaQi5ZUyVvNsiWMEHgBbWrWf6IO9+XOPBFaZvAxSXT+N0m4KcfXgHARa+w90JSYQ39AxBznVhzCDVqRccwjfyh469Il+YbS7JN0lR3otTFmah7Ge8KxVMQ0mOxGP7Ppg8QNUrmf6cW11fhuWgBuA5T/t5QU=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Company = _t, Date = _t, #"Sponsor Name" = _t, #"Valuation (in Millions)" = _t, #"Deal Size (in Millions)" = _t, Geography = _t, Country = _t, Sector = _t, Status = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Company", type text}, {"Date", type date}, {"Sponsor Name", type text}, {"Valuation (in Millions)", Int64.Type}, {"Deal Size (in Millions)", Int64.Type}, {"Geography", type text}, {"Country", type text}, {"Sector", type text}, {"Status", type text}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Company", Order.Ascending}, {"Date", Order.Ascending}}),
    #"Replaced Value" = Table.ReplaceValue(#"Sorted Rows","",null,Replacer.ReplaceValue,{"Sponsor Name", "Geography", "Country", "Sector", "Status"}),
    #"Filled Down" = Table.FillDown(#"Replaced Value",{"Sponsor Name", "Valuation (in Millions)", "Deal Size (in Millions)", "Geography", "Country", "Sector", "Status"}),
    #"Grouped Rows" = Table.Group(#"Filled Down", {"Company"}, {{"Date", each List.Max([Date]), type date}, {"Sponsor Name", each List.Max([Sponsor Name]), type text}, {"Valuation (in Millions)", each List.Max([#"Valuation (in Millions)"]), type number}, {"Deal Size (in Millions)", each List.Max([#"Deal Size (in Millions)"]), type number}, {"Geography", each List.Max([Geography]), type text}, {"Country", each List.Max([Country]), type text}, {"Sector", each List.Max([Sector]), type text}, {"Status", each List.Max([Status]), type text}})
in
    #"Grouped Rows"

Hope this is what you want.

View solution in original post

3 REPLIES 3
rajulshah Solution Sage
Solution Sage

Re: Creating a Summary Table from an existing table

Hello @rjsidek,

 

Please try following M query code :

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hZBfC4IwFMW/iuw52N1MykfpD/QSgb1JD7YGDmyG0z5/904zTSi43N2xwzm/3SxjOVswkFxILkHEeDnp2lU2EDgKAOyS2rGqmyJInCH9pjDWn5V17V3XOCaqMU/NLoveMRo5diWjYaQi5ZUyVvNsiWMEHgBbWrWf6IO9+XOPBFaZvAxSXT+N0m4KcfXgHARa+w90JSYQ39AxBznVhzCDVqRccwjfyh469Il+YbS7JN0lR3otTFmah7Ge8KxVMQ0mOxGP7Ppg8QNUrmf6cW11fhuWgBuA5T/t5QU=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Company = _t, Date = _t, #"Sponsor Name" = _t, #"Valuation (in Millions)" = _t, #"Deal Size (in Millions)" = _t, Geography = _t, Country = _t, Sector = _t, Status = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Company", type text}, {"Date", type date}, {"Sponsor Name", type text}, {"Valuation (in Millions)", Int64.Type}, {"Deal Size (in Millions)", Int64.Type}, {"Geography", type text}, {"Country", type text}, {"Sector", type text}, {"Status", type text}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Company", Order.Ascending}, {"Date", Order.Ascending}}),
    #"Replaced Value" = Table.ReplaceValue(#"Sorted Rows","",null,Replacer.ReplaceValue,{"Sponsor Name", "Geography", "Country", "Sector", "Status"}),
    #"Filled Down" = Table.FillDown(#"Replaced Value",{"Sponsor Name", "Valuation (in Millions)", "Deal Size (in Millions)", "Geography", "Country", "Sector", "Status"}),
    #"Grouped Rows" = Table.Group(#"Filled Down", {"Company"}, {{"Date", each List.Max([Date]), type date}, {"Sponsor Name", each List.Max([Sponsor Name]), type text}, {"Valuation (in Millions)", each List.Max([#"Valuation (in Millions)"]), type number}, {"Deal Size (in Millions)", each List.Max([#"Deal Size (in Millions)"]), type number}, {"Geography", each List.Max([Geography]), type text}, {"Country", each List.Max([Country]), type text}, {"Sector", each List.Max([Sector]), type text}, {"Status", each List.Max([Status]), type text}})
in
    #"Grouped Rows"

Hope this is what you want.

View solution in original post

rjsidek Helper II
Helper II

Re: Creating a Summary Table from an existing table

Hi Rajul,

 

Sorry but I am rather new here on PowerBI. How would I add this code on query editor? I am not sure I know how.

Highlighted
rajulshah Solution Sage
Solution Sage

Re: Creating a Summary Table from an existing table

@rjsidek,

 

Please go to below link. It shows how to achieve it.

Video

 

Hope this helps.

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors