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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
adoalan
Helper III
Helper III

MAX SQL Help

Hi all,

 

Can you help me on this SQL query. I need to get only the first value or highest values by PH.pledgeid

 

select max(PH.pledgeid), BH.BATCHDESCRIPTION, count (BH.BATCHDESCRIPTION) as BDCount from PH
inner join BD on BD.SERIALNUMBER = PH.SERIALNUMBER and BD.SOURCECODE = PH.SOURCECODE
inner join BH on BH.ADMITNAME = BD.ADMITNAME
WHERE PH.PAYMENTTYPE ='Standing Order' and BATCHDESCRIPTION<>'Refunds Paid'
and PH.SERIALNUMBER in (Select SERIALNUMBER from C
where BLOCKPURCHASESREASON = 'Migrate')
Group By PH.pledgeid, BH.BATCHDESCRIPTION
Order by count (BH.BATCHDESCRIPTION) DESC

 

adoalan_0-1670494688240.png

You can see the example below and I need only the highest for this pledge id

adoalan_1-1670494742348.png

Many thanks 

ado

 

2 REPLIES 2
v-yalanwu-msft
Community Support
Community Support

Hi, @adoalan ;

You need to find the maximum value with dax, right, if so, you can try:

max =
CALCULATE ( MAX ( 'table'[count] ), ALLEXCEPT ( 'table', 'table'[pledge id] ) )

 
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi 

 

I needed in SQL not in power BI 

Helpful resources

Announcements
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.