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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
mikeys
New Member

DAX Summarizecolumns and then countrows per group

Hi,

I have query with 3 dimensions (Continent/CountryRegion/City) part of paginated report.

I would like to highlight only those child groups where there is 1 item.

So I need to get a count of items per each parent group. 

In this case, let's write the query, to be more exact.

EVALUATE
VAR __t1 =
SUMMARIZECOLUMNS (
Customer[Continent],
Customer[CountryRegion],
Customer[City],
"Amount", [Sales Amount]
)

RETURN
GROUPBY(
__t1,
Customer[Continent],
Customer[CountryRegion],
"Count" , countX(CURRENTGROUP(), Customer[CountryRegion] )
) ORDER BY Customer[Continent] DESC

 

Which brings me this

mikeys_0-1705415967507.png

 

Result I am looking for is

mikeys_1-1705415967360.png

 

 

And in a case where I have 3 dimensions
EVALUATE
VAR __t1 =
SUMMARIZECOLUMNS (
Customer[Continent],
Customer[CountryRegion],
Customer[City],
"Amount", [Sales Amount]
)

RETURN
GROUPBY(
__t1,
Customer[Continent],
Customer[CountryRegion],
Customer[City],
"Count" , countX(CURRENTGROUP(), Customer[City] )
) ORDER BY Customer[Continent] DESC

I get

 

 

But I would like to see

mikeys_0-1705416184710.png

 

 

 

How should I approach this?
Thank you!

2 REPLIES 2
Mikeysw
New Member

Thank you for your answer!

I've tried your query but it gives me an error

Mikeysw_0-1705483272979.png

 

123abc
Community Champion
Community Champion

To achieve the desired result, you can use the following approach:

 

EVALUATE
VAR __t1 =
SUMMARIZECOLUMNS (
Customer[Continent],
Customer[CountryRegion],
Customer[City],
"Amount", [Sales Amount]
)

VAR __t2 =
SUMMARIZECOLUMNS (
__t1,
Customer[Continent],
Customer[CountryRegion],
"Count", COUNTROWS(__t1)
)

RETURN
GROUPBY(
__t2,
Customer[Continent],
Customer[CountryRegion],
"Count", COUNTROWS(CURRENTGROUP())
) ORDER BY Customer[Continent] DESC, Customer[CountryRegion] DESC

 

In this query:

  1. The first SUMMARIZECOLUMNS creates a table (__t1) with the necessary dimensions and the "Amount" measure.
  2. The second SUMMARIZECOLUMNS adds another level of summarization (__t2) based on the first table (__t1), and calculates the count of rows for each combination of Continent and CountryRegion.
  3. The final GROUPBY groups the second table (__t2) by Continent and CountryRegion and calculates the count of rows for each group.

This should give you the desired result, showing the count of items per each parent group, and only highlighting those groups where there is 1 item.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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