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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
amirabedhiafi
Impactful Individual
Impactful Individual

Get the max of the sum total defect quantity

I have this following query  :

SELECT * FROM (
SELECT Vendor,[Material Type]
,SUM([Total Defect Qty]) AS [Sum]
,YEAR([Date]) as [Date]
, RANK() OVER(PARTITION BY Vendor,YEAR([Date]) ORDER BY SUM([Total Defect Qty]) DESC) AS rn
FROM SupplierQuality
GROUP BY Vendor,[Material Type],YEAR([Date])
) AS T
WHERE T.rn=1 
ORDER BY Vendor,[Date],[Sum] DESC

 

I need to do the same in Power BI but my data source isn't a SQL Server database, it's an Excel file.

How can I get the max of the summed [Total Defect Qty] ?

I have the following data returned by the query above :

Captured.PNG

For example, for the vendor Abata I need to get only the max Sum for 2018 and 2019

 

 

 

 

Amira Bedhiafi
Full Stack Business Intelligence Consultant @Capgemini
1 ACCEPTED SOLUTION
amirabedhiafi
Impactful Individual
Impactful Individual

I ended up creating a calculated table : 

GroupedTable = GROUPBY(
SupplierQuality,
SupplierQuality[Vendor],
SupplierQuality[Material Type],
SupplierQuality[Date].[Année],
"Sum Total Defect Qtity",
SUMX(
CURRENTGROUP(),
SupplierQuality[Total Defect Qty]
)
)
 
Then created a measure like below : 
Max in group = IF(CALCULATE(MAX(GroupedTable[Sum Total Defect Qtity])
,ALLEXCEPT(GroupedTable,
GroupedTable[SupplierQuality_Vendor]))=MAX(GroupedTable[Sum Total Defect Qtity])
,1,0)
Amira Bedhiafi
Full Stack Business Intelligence Consultant @Capgemini

View solution in original post

2 REPLIES 2
amirabedhiafi
Impactful Individual
Impactful Individual

I ended up creating a calculated table : 

GroupedTable = GROUPBY(
SupplierQuality,
SupplierQuality[Vendor],
SupplierQuality[Material Type],
SupplierQuality[Date].[Année],
"Sum Total Defect Qtity",
SUMX(
CURRENTGROUP(),
SupplierQuality[Total Defect Qty]
)
)
 
Then created a measure like below : 
Max in group = IF(CALCULATE(MAX(GroupedTable[Sum Total Defect Qtity])
,ALLEXCEPT(GroupedTable,
GroupedTable[SupplierQuality_Vendor]))=MAX(GroupedTable[Sum Total Defect Qtity])
,1,0)
Amira Bedhiafi
Full Stack Business Intelligence Consultant @Capgemini
mahoneypat
Microsoft Employee
Microsoft Employee

In this ribbon in the query editor, click on the Group By button, choose advanced and set up Group By on Vendor, Material Type, and Date columns, and then choose Max as the aggregation of the Sum column.

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors