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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
shanemc1
Frequent Visitor

Select top 1 Min Value with Group By in Power Bi

I have the following SQL where it will select the lowest proposal price from from a list of proposals based on a set of Enquiries. 

 

For example if I have 10 enquiries with 10 proposals attatched I have 100 proposals. I want to select the min price for each enquiry so ideally I will end up with 10 minimum values for each enquiry.

 

Here is the sql code which gets exactly what I need.

 

SELECT distinct(pkenquiries), (SELECT TOP 1 TotalProposalPrice / NULLIF(evp.CoversionRate, 0) FROM EnquiryVenueProposal evp where e.pkEnquiries = evp.EnquiryId and EnquiryVenueProposalStatusId = 1 order by TotalProposalPrice desc)
                 FROM Enquiries e
                 WHERE EnquiryStatusId = 70 and TestEnquiry = 0
group by pkEnquiries

How would I go about creatuing a mesaure in power BI to ideally present with me a list of distinct enquiries that have the minimum proposal price attatched?

 

I currently have something like 

Min Proposal of Lost Enquiries = CALCULATE (
    LASTNONBLANK ( 'Enquiries'[pkEnquiries], 1 ),
    FILTER ( TOPN ( 1, VALUES ( 'EnquiryVenueProposal'[TotalProposalPrice] ), [TotalProposalPrice], DESC ), TRUE () )
) 

But this does'nt return the correct data at all?

 
1 REPLY 1
v-lili6-msft
Community Support
Community Support

HI, @shanemc1

You may try to adjust your formula like below:

 

Min Proposal of Lost Enquiries = CALCULATE (
    LASTNONBLANK ( 'Enquiries'[pkEnquiries], 1 ),
    FILTER ( TOPN ( 1, VALUES ( 'EnquiryVenueProposal'[TotalProposalPrice] ), [TotalProposalPrice], ASC ), TRUE () )
)

or

Min Proposal of Lost Enquiries = CALCULATE (
    LASTNONBLANK ( 'Enquiries'[pkEnquiries], 1 ),
    FILTER ( TOPN ( 1, 'EnquiryVenueProposal', [TotalProposalPrice], ASC ), TRUE () )
)

If it is not your case, please share pbix file or some data sample and expected output . You can upload it to OneDrive and post the link here. Do mask sensitive data before uploading.

 

 

 

Best Regards,

Lin

 

 

 

 

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

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.