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
JacobSzp
Regular Visitor

Count of Records Within One Column

Hi all,

 

Looking to solve the below issue within Power Query, not so much with dax.

 

Hopefully the below illustrates the issue clearly.

 

JacobSzp_0-1669384795970.png

 

Thanks,

Jacob.

 

2 ACCEPTED SOLUTIONS
Luis98
Resolver II
Resolver II

Hi @JacobSzp 

 

You can duplicate this table, then group the column of colour by count of name, and then merge with the other table by colour column

View solution in original post

BA_Pete
Super User
Super User

Hi Jacob,

 

Select your [Fave Colour] column and go to Home tab > Group By.

In the dialog, keep the default count aggregated column, and also add another one using the 'All Rows' aggregator.

Expand the nested table column back out again.

 

Example Code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8s1MzlbSUQpKTVGK1YlW8krMTkXiBpekloH4kak5OfnlYCGfzCpUAd/EomxUkYCMzBxUkeDEosQMNG35QL5TTmmqUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"Fave Colour" = _t]),
    groupRows = Table.Group(Source, {"Fave Colour"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"allRows", each _, type table [Name=nullable text, Fave Colour=nullable text]}}),
    expansAllRows = Table.ExpandTableColumn(groupRows, "allRows", {"Name"}, {"Name"})
in
    expansAllRows

 

Example Output:

BA_Pete_0-1669646886060.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

3 REPLIES 3
BA_Pete
Super User
Super User

Hi Jacob,

 

Select your [Fave Colour] column and go to Home tab > Group By.

In the dialog, keep the default count aggregated column, and also add another one using the 'All Rows' aggregator.

Expand the nested table column back out again.

 

Example Code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8s1MzlbSUQpKTVGK1YlW8krMTkXiBpekloH4kak5OfnlYCGfzCpUAd/EomxUkYCMzBxUkeDEosQMNG35QL5TTmmqUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"Fave Colour" = _t]),
    groupRows = Table.Group(Source, {"Fave Colour"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"allRows", each _, type table [Name=nullable text, Fave Colour=nullable text]}}),
    expansAllRows = Table.ExpandTableColumn(groupRows, "allRows", {"Name"}, {"Name"})
in
    expansAllRows

 

Example Output:

BA_Pete_0-1669646886060.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




v-jingzhang
Community Support
Community Support

Hi @JacobSzp 

 

Have you tried @Luis98 's solution? It works well!

 

In addition, here is another solution if you want to add a custom column directly without duplicating a query. 

let favColor = [Fave Colour] in List.Count(List.Select(#"previous step"[Fave Colour], each _ = favColor))

vjingzhang_0-1669628964333.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Luis98
Resolver II
Resolver II

Hi @JacobSzp 

 

You can duplicate this table, then group the column of colour by count of name, and then merge with the other table by colour column

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.

Top Solution Authors