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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
john-paul
Frequent Visitor

PQ Countifs based on two columns

Hi,

 

I loaded the below table (first 4 columns) into Power Query, and want to add a column that counts the total number of occurances of the Product and Region combinations.

 

I tried Group By on Product and Region, but Name and S column were removed, and I would like to retain them

 

Hope someone can help.

 

ProductRegionName$Desired Result
123NorthDavid1003
123NorthDavid1003
123NorthEric1003
456CentralEric1002
456CentralPeter1002
789CentralPeter1001
789NorthTom1001
1010NorthTom1001
123SouthTom1001

 

Thanks,

 

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @john-paul 

Place the following M code in a blank query to see the steps:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJR8ssvKskA0i6JZZkpQNrQwEApVoc0WdeizGQkSRNTMyDPOTWvpCgxh7B0QGpJahGSvLmFJRHyMLtD8nOR3WVgaIBbEuzo4PxSdLlYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, Region = _t, Name = _t, #"$" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", Int64.Type}, {"Region", type text}, {"Name", type text}, {"$", Int64.Type}}),

    #"Grouped Rows" = Table.Group(#"Changed Type", {"Product", "Region"}, {{"aux", each _},{"Count", each Table.RowCount(_), Int64.Type}}),
    #"Expanded aux" = Table.ExpandTableColumn(#"Grouped Rows", "aux", {"Name", "$"}, {"Name", "$"})
in
    #"Expanded aux"

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

2 REPLIES 2
AlB
Community Champion
Community Champion

Hi @john-paul 

Place the following M code in a blank query to see the steps:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJR8ssvKskA0i6JZZkpQNrQwEApVoc0WdeizGQkSRNTMyDPOTWvpCgxh7B0QGpJahGSvLmFJRHyMLtD8nOR3WVgaIBbEuzo4PxSdLlYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, Region = _t, Name = _t, #"$" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", Int64.Type}, {"Region", type text}, {"Name", type text}, {"$", Int64.Type}}),

    #"Grouped Rows" = Table.Group(#"Changed Type", {"Product", "Region"}, {{"aux", each _},{"Count", each Table.RowCount(_), Int64.Type}}),
    #"Expanded aux" = Table.ExpandTableColumn(#"Grouped Rows", "aux", {"Name", "$"}, {"Name", "$"})
in
    #"Expanded aux"

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

john-paul
Frequent Visitor

Thanks AIB for your help.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors