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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
heriberto_mb
Frequent Visitor

How to show the rows with more data in PowerQuery/PowerBI?

I'm struggling how to identify the rows that have more data based on a column, in this case: Owner, if there is no Owner at all, show the row with no owner. PowerQuery is preferable, but if that is not possible, using PowerBI

 

Example:

ColorStateOwner
BlueMI 
BlueMISnoopy
YellowAZCharlie
YellowAZCharlie
RedCO 
RedCO 

 

Desired Result:

ColorStateOwner
BlueMISnoopy
YellowAZCharlie
RedCO 
3 ACCEPTED SOLUTIONS
BabyYoda
Frequent Visitor

This is more steps. I would personally try to push this logic back to the source but it can be done in power query.

To make this work in power query I had to create another copy  of the table and join the original table to the copy.  I also had to make a key with a merge on Owner, State, and, Color in both the copy and the original  I used that to join in the merge step.  Then I pulled the toy from the joined table.

BabyYoda_0-1725399764030.png

 

 

BabyYoda_1-1725399940129.png

 

View solution in original post

Omid_Motamedise
Resident Rockstar
Resident Rockstar

you can use group by command to solve this.

use the next formula



let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Color", type text}, {"State", type text}, {"Owner", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Color", "State"}, {{"Count", each Text.Combine(List.Distinct(([Owner])))}})
in
#"Grouped Rows"



result in 

 

 

Omid_Motamedise_1-1725401544392.png

 

View solution in original post

dufoq3
Super User
Super User

Hi @heriberto_mb, check this:

 

Result

dufoq3_0-1725456555761.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsopTVXSUfL1BBLJiUVAUilWB1W4pCgxMw9IB+fl5xdUgqUjU3Ny8suBYo5RQCIpMScHSDlnJBblZKZiUVCZX5kPMzkoNQWk1h9IpOSD9eEUjgUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Color = _t, State = _t, Toy = _t, Owner = _t]),
    ReplacedValue = Table.ReplaceValue(Source,"",null,Replacer.ReplaceValue,{"Owner"}),
    GroupedRows = Table.Group(ReplacedValue, {"Color", "State"}, {{"All", each if List.Count(List.Select([Owner], (x)=> x = null)) = List.Count([Owner]) then Table.FirstN(_, 1) else Table.FirstN(Table.SelectRows(_, (x)=> x[Owner] <> null), 1), type table}}),
    CombinedAll = Table.Combine(GroupedRows[All])
in
    CombinedAll

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

5 REPLIES 5
dufoq3
Super User
Super User

Hi @heriberto_mb, check this:

 

Result

dufoq3_0-1725456555761.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsopTVXSUfL1BBLJiUVAUilWB1W4pCgxMw9IB+fl5xdUgqUjU3Ny8suBYo5RQCIpMScHSDlnJBblZKZiUVCZX5kPMzkoNQWk1h9IpOSD9eEUjgUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Color = _t, State = _t, Toy = _t, Owner = _t]),
    ReplacedValue = Table.ReplaceValue(Source,"",null,Replacer.ReplaceValue,{"Owner"}),
    GroupedRows = Table.Group(ReplacedValue, {"Color", "State"}, {{"All", each if List.Count(List.Select([Owner], (x)=> x = null)) = List.Count([Owner]) then Table.FirstN(_, 1) else Table.FirstN(Table.SelectRows(_, (x)=> x[Owner] <> null), 1), type table}}),
    CombinedAll = Table.Combine(GroupedRows[All])
in
    CombinedAll

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Omid_Motamedise
Resident Rockstar
Resident Rockstar

you can use group by command to solve this.

use the next formula



let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Color", type text}, {"State", type text}, {"Owner", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Color", "State"}, {{"Count", each Text.Combine(List.Distinct(([Owner])))}})
in
#"Grouped Rows"



result in 

 

 

Omid_Motamedise_1-1725401544392.png

 

BabyYoda
Frequent Visitor

This is more steps. I would personally try to push this logic back to the source but it can be done in power query.

To make this work in power query I had to create another copy  of the table and join the original table to the copy.  I also had to make a key with a merge on Owner, State, and, Color in both the copy and the original  I used that to join in the merge step.  Then I pulled the toy from the joined table.

BabyYoda_0-1725399764030.png

 

 

BabyYoda_1-1725399940129.png

 

BabyYoda
Frequent Visitor

Use the Group by Power Query Transformation and use a Max on Owner.  Group by the other two fields.  See screenshot

BabyYoda_0-1725378620233.png

 

Thank you very much that worked well, but found another case, I will post it as a new question.

 

Example:

 

ColorStateToyOwner
BlueMIcar 
BlueMItrainSnoopy
YellowAZballCharlie
YellowAZyoyo 
RedCOdoll 
RedCOdoll 

 

Desired Result: No matter what Toy is it, report only the row which has an owner if it exists.

ColorStateToyOwner
BlueMItrainSnoopy
YellowAZballCharlie
RedCOdoll 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors