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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
PA20
Frequent Visitor

Count invoice ID in category based on highest invoice line associated with invoice ID

Dear all. 

I am hoping for your assistance. I have a dataset with invoice data and I would like to only count the InvoiceID in the categories where the spend is the highest. 

 

Thanks in advance

PA20_0-1705920392463.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @PA20 ,

Please try to create a new column with below dax formula:

Column =
VAR cur_id = [InvoiceID]
VAR cur_spend = [Spend]
VAR tmp =
    FILTER ( 'Table', [InvoiceID] = cur_id )
VAR max_speed =
    MAXX ( tmp, [Spend] )
VAR tmp1 =
    FILTER ( tmp, [Spend] = max_speed )
VAR ctn =
    COUNTROWS ( tmp1 )
RETURN
    IF ( cur_spend = max_speed, ctn, BLANK () )

vbinbinyumsft_0-1705993496803.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @PA20 ,

Please try to create a new column with below dax formula:

Column =
VAR cur_id = [InvoiceID]
VAR cur_spend = [Spend]
VAR tmp =
    FILTER ( 'Table', [InvoiceID] = cur_id )
VAR max_speed =
    MAXX ( tmp, [Spend] )
VAR tmp1 =
    FILTER ( tmp, [Spend] = max_speed )
VAR ctn =
    COUNTROWS ( tmp1 )
RETURN
    IF ( cur_spend = max_speed, ctn, BLANK () )

vbinbinyumsft_0-1705993496803.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

PA20
Frequent Visitor

Thank you for your swift reply @amitchandak . Spend is not a meassure, perhaps amount would have been a better naming option. The only use I have for the amount in this instance is as a sorting mechanism for my count by category - if that makes sense.

 

All the best.

amitchandak
Super User
Super User

@PA20 , I think you want to display those use TOPN with 1 of Index

 

Assuming spend is a measure

 

calculate([Spend], keepfilters(index(1, allselected(Table[InvoiceID], Table[Category]), orderBy([Spend], desc) ,partitionBy(Table[Category]))) )

 

 

Power BI Index function: Top/Bottom Performer by name and value- https://youtu.be/HPhzzCwe10U

 

TOPN: https://youtu.be/QIVEFp-QiOk
TOPN with Numeric Parameter -https://youtu.be/cN8AO3_vmlY?t=26448

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

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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