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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kagy100
Advocate II
Advocate II

How to merge rows so that there are no blanks

Hi All,

 

Here is what the data looks like : Current State

YearTargetCurrent ValuePercentageAccount
17/18 1.2651 Account A
18/19 1.357714467 Account A
18/19  -7.32 %Account A
19/20 0.72 Account A
19/20  46.97 %Account A
20/21   Account A

 

This is what I want the data to look like: Desired State

YearTargetCurrent ValuePercentageAccount
17/18 1.2651 Account A
18/19 1.357714467-7.32 %Account A
19/20 0.7246.97 %Account A
20/21   Account A

 

How do I merge the rows so I have all data for the year in one row.

 

Thanks

1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

@kagy100 

Are you always wanting the maximum value? Is there ever any difference in text that needs reconciled/merged? 

 

I would suggest using Power Query for this - so click Transform Data. 

 

If all the values with blanks are numeric, then you can simply use a MAX aggregation, if they are text, we will need to add a step first. Click "Group By", select the 'Advanced' option. 

Choose Date for your first Group by column. Add Grouping> choose Account for your second Group by column. 

 

Then you will need to add a column for every merged value that you want, so in the sample you provided, choose as in the image below: 

 

AllisonKennedy_1-1604901908116.png

 

Or paste this code into Advanced Editor to see it work: 

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hcy9CoAgFIbhWxGhzdRz/Dk6eh3i5F5L3X8KElFCwzt88PDlzIEUBC44a4FE72CMVOt+bgdLvIjGgoJ4M+OIwFpPv7a3kjTIlq+LCvUwWhLOzx6oZ72MNDlDrRAe7vVULg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Year = _t, Target = _t, #"Current Value" = _t, Percentage = _t, Account = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", type text}, {"Target", type number}, {"Current Value", type number}, {"Percentage", Percentage.Type}, {"Account", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Year", "Account"}, {{"Target", each List.Max([Target]), type nullable text}, {"Percentage", each List.Max([Percentage]), type nullable number}, {"Current Value", each List.Max([Current Value]), type nullable number}})
in
#"Grouped Rows"

 

 

 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

5 REPLIES 5
AllisonKennedy
Super User
Super User

@kagy100 

Are you always wanting the maximum value? Is there ever any difference in text that needs reconciled/merged? 

 

I would suggest using Power Query for this - so click Transform Data. 

 

If all the values with blanks are numeric, then you can simply use a MAX aggregation, if they are text, we will need to add a step first. Click "Group By", select the 'Advanced' option. 

Choose Date for your first Group by column. Add Grouping> choose Account for your second Group by column. 

 

Then you will need to add a column for every merged value that you want, so in the sample you provided, choose as in the image below: 

 

AllisonKennedy_1-1604901908116.png

 

Or paste this code into Advanced Editor to see it work: 

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hcy9CoAgFIbhWxGhzdRz/Dk6eh3i5F5L3X8KElFCwzt88PDlzIEUBC44a4FE72CMVOt+bgdLvIjGgoJ4M+OIwFpPv7a3kjTIlq+LCvUwWhLOzx6oZ72MNDlDrRAe7vVULg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Year = _t, Target = _t, #"Current Value" = _t, Percentage = _t, Account = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", type text}, {"Target", type number}, {"Current Value", type number}, {"Percentage", Percentage.Type}, {"Account", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Year", "Account"}, {{"Target", each List.Max([Target]), type nullable text}, {"Percentage", each List.Max([Percentage]), type nullable number}, {"Current Value", each List.Max([Current Value]), type nullable number}})
in
#"Grouped Rows"

 

 

 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Thank You @AllisonKennedy I followed your instructions and I was able to achieve my desired result.

You're welcome! Glad you got what you needed. 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

amitchandak
Super User
Super User

@kagy100 , You have aggregate in power Query

https://radacad.com/power-bi-aggregation-step-1-create-the-aggregated-table

 

Or use summarize in DAX , Create new table

Summarize(Table,Table[Year],"Target",Min(Table[Target]),"Current Value", min(Table[Current Value]),"Percentage",min(Table[Percentage]),"Account",min(Table[Account]))

or

Summarize(Table,Table[Year],"Target",Max(Table[Target]),"Current Value", Max(Table[Current Value]),"Percentage",max(Table[Percentage]),"Account",max(Table[Account]))

 

Thank You for taking the time to assist me with the data query. I tried the Group By Function in the Query Editor and was able to achieve the desired output. I will keepy your DAX technique in mind for future cases. 🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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