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
lasmithfla
Helper I
Helper I

Need help with grouping values based on a measure

This is a sample of the data.

The number of Sales is a measure so not a column in the table.

I'm struggling with a calc that will count the number of customers bases on the sales ranges.  I can't do anything that is counting rows in the original sales table because the ones with 0 value do not exist in that table.

So I'm thinking the calc needs to create a temp table like i have pasted below in the green to base the calc. on.

Hope this makes sense.

 

lasmithfla_0-1647549393370.png

 

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@lasmithfla 

you can try this

Column = 
VAR _min='Sales Range'[min]
VAR _max='Sales Range'[max]
VAR tbl=SUMMARIZE(Customer,Customer[Customer],"no of sales",COUNTROWS(RELATEDTABLE(Sales))+0)
return COUNTX(FILTER(tbl,[no of sales]>=_min&&[no of sales]<=_max),[no of sales])+0

1.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
ryan_mayu
Super User
Super User

@lasmithfla 

you can try this

Column = 
VAR _min='Sales Range'[min]
VAR _max='Sales Range'[max]
VAR tbl=SUMMARIZE(Customer,Customer[Customer],"no of sales",COUNTROWS(RELATEDTABLE(Sales))+0)
return COUNTX(FILTER(tbl,[no of sales]>=_min&&[no of sales]<=_max),[no of sales])+0

1.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




coskuersanli
Resolver III
Resolver III

Hi @lasmithfla 

I believe we can use SUMMARISE() and COUNTROWS(). If 0's don't show up in table, we can add ISBLANK() to calculation. Can you try something like this one please? 🙂

 

VAR summ_table =
		SUMMARISE
			(
				Table,
				Customer,
				"new_column",
				number_of_sales
			)

RETURN

CALCULATE
	(
		COUNTROWS(summ_table),
		FILTER
			(
				summ_table,
				new_column >= sales_ranges_min &&
				new_column < sales_ranges_max
			)
	)
				
				

 

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.