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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
jgb231
Frequent Visitor

Distinct Count based on the sum of a metric

Hi,

I have a current requirement to calculate the distinct number of customers who are buying producting within a given time period. This time period could be 1 day, 10 days, monthly, quarterly, etc.  The table is at the invoice line level.  The requirement is that within the given time period selected, to be counted, the customer had to have done business in which the sum of the sales amount is not zero.  

The current calculation is as follows:

CustomerCount:=CALCULATE(DISTINCTCOUNT(Transactions[CustomerCount]),
FILTER(Transactions,[NetSales]<>0 )
)

The filter measure is:

NetSales:=SUMX(filter(Transactions,Transactions[system_currency_adj_3rd_party_line_total_amt]<>0&&Transactions[is_revenue_ind]=1&&Transactions[Transaction_Type_Aggregate]="Net Sales"),Transactions[system_currency_adj_3rd_party_line_total_amt])

 

I still end up with a handful of customers that are counted because their line items are both positive (invoice) and negative (credit) but should not because their total NetSales for the given period is 0.

 

I tried the following:

CustomerCounttest:=
CALCULATE(
DISTINCTCOUNT( Transactions[ParentPartnerID]),
FILTER (
ALLEXCEPT(Transactions,
CALCULATE(sum(Transactions[NetInvoiceAmt]))<>0
)
)

 

but I end up with a memory exceeds the visualization error

 

This cannot be that hard of a scenario to solve for.  Please note this is currently deployed in Azure Analysis Services.

 

Any help is appreciated!

 

Joe

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@jgb231 , Not very clear, do you want to count customer net sales <> 0 where net sales is a measure. Ideally if there no negative amount, you are getting that only.

 

Otherwise you need to have a measure like

Example measure

countx(filter(Values(customer[Customer id]),[Net sales]<>0 ), [Customer id])

 

Try a measure like above

if not

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@jgb231 , Not very clear, do you want to count customer net sales <> 0 where net sales is a measure. Ideally if there no negative amount, you are getting that only.

 

Otherwise you need to have a measure like

Example measure

countx(filter(Values(customer[Customer id]),[Net sales]<>0 ), [Customer id])

 

Try a measure like above

if not

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

The countx did it!  Thank you so much!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.