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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

SQL outer apply with top 1 table

Hi

 

Is there a way to convert this query for the service? It works well on the Desktop version but not in the service

 

declare @From date
declare @to date
SELECT t1.*,t2.*,t3.*
FROM Fact f

Cross apply
(
select top 1
from dimension1 d1
where f.id=d1.id
and datefrom >=@From  and dateto <=@To
order by datefrom desc) t1

outer apply

(select top 1
from dimension2 d2
where f.id2=d2.id
and datefrom >=@From  and dateto <=@To
order by datefrom desc) t2

outer apply

(select top 1
from dimension2 d2
where f.id3=d2.id
and datefrom >=@From  and dateto <=@To
order by datefrom desc) t3

4 REPLIES 4
lbendlin
Super User
Super User

As I understand it you only need it for table valued functions.  CTEs are convenience constructs for subqueries, and joins work (mostly) the same way as applies.

 

SQL Server CROSS APPLY and OUTER APPLY (mssqltips.com)

Anonymous
Not applicable

I don't understand your response, I need to convert the query above to powerbi, there are other ways of doing apply type functions, but neither work with power bi in the format of the query.

lbendlin
Super User
Super User

I don't see any functions. You should be able to do the same with a standard left join.

Anonymous
Not applicable

These are table expressions being joined, so PBI needs to dynamically filter the apply expressions at run time for top 1's. It's not the same as a LEFT JOIN  to a table

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Kudoed Authors