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