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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Dankang
Regular Visitor

Dynamic Grouping via Support table

 Hi Guys,

 

Hope you all had anice weekend.

 

I am currently learning how to make dynamic grouping via support table.

 

Customer Sales by Group =
CALCULATE( [Total Sales],
FILTER( VALUES( Customers[Customer Names] ),
COUNTROWS(
FILTER( 'Customer Groups',
RANKX( ALL( Customers[Customer Names] ), [Total Sales],,DESC ) > 'Customer Groups'[Min]
&& RANKX( ALL( Customers[Customer Names] ), [Total Sales],, DESC ) <= 'Customer Groups'[Max] ) )
> 0 ))

 

here is the fomula that i just learnt. So basically i created a new table that has 'Top 5', '5 to 20' and 'the rest' that evaulates the groups.

 

2 questions.

1. Why does there need be countrows >0 ? does the fomula not work if i dont have the countrows function there?

2. Why do i need all[customer names] in RANKX? if i remove all filters for Customers names by using 'ALL' fuction the total sales returns the same and i won't be able to rank customers by 'Sales Total'?

 

Thanks in advance for your help.

 

Cheers,

1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @Dankang,

 

#1. It is used to ignore result who not suitable for your conditions.(count row with blank table will blank result, power bi will recognize it as zero)

 

#2. All function is used to break filter effect to let formula calculated on whole table.

Managing “all” functions in DAX: ALL, ALLSELECTED, ALLNOBLANKROW, ALLEXCEPT

 

Regards,

Xiaoxin Sheng

View solution in original post

2 REPLIES 2
Dankang
Regular Visitor

 Hi Guys,

 

Hope you all had a nice weekend.

 

I am currently learning how to make dynamic grouping via support table.

 

Customer Sales by Group =
CALCULATE( [Total Sales],
FILTER( VALUES( Customers[Customer Names] ),
COUNTROWS(
FILTER( 'Customer Groups',
RANKX( ALL( Customers[Customer Names] ), [Total Sales],,DESC ) > 'Customer Groups'[Min]
&& RANKX( ALL( Customers[Customer Names] ), [Total Sales],, DESC ) <= 'Customer Groups'[Max] ) )
> 0 ))

 

here is the fomula that i just learnt. So basically i created a new table that has 'Top 5', '5 to 20' and 'the rest' that evaulates the groups.

 

2 questions.

1. Why does there need be 'countrows >0' ? does the fomula not work if i dont have the countrows function there?

2. Why do i need all[customer names] in RANKX? if i remove all filters for Customers names by using 'ALL' fuction the total sales returns the same and i won't be able to rank customers by 'Sales Total'?

 

Thanks in advance for your help.

 

Cheers,

Anonymous
Not applicable

HI @Dankang,

 

#1. It is used to ignore result who not suitable for your conditions.(count row with blank table will blank result, power bi will recognize it as zero)

 

#2. All function is used to break filter effect to let formula calculated on whole table.

Managing “all” functions in DAX: ALL, ALLSELECTED, ALLNOBLANKROW, ALLEXCEPT

 

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.