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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
martynas
New Member

Measure SQL query

Hi,

 

What is the best way to offload Measure calculation to custom SQL query limited on start and end date? My data is access via DirectQuery connected to PostgreSQL. 

 

I am trying to calculate the median (50th percentile) of large data set with many millions of rows and would like to do that on SQL server, not in PowerBI.

 

Found the possible solution here - https://www.youtube.com/watch?v=iiNDq2VrZPY , but it does not looks like 100%, what I need.

 

Best regards,

Martynas

1 ACCEPTED SOLUTION

Hi @martynas ,

 

Based on your description, do you want to pass the slicer value to the SQL query statement? Complete the calculation in SQL?

Refer to

power-bi-desktop-query-parameters-part2-dynamic-data-masking-and-query-parameters 

pass-parameters-to-sql-queries 

You can also try to use SSAS to connect live with powerbi.

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@martynas , In case of the direct query you can record the queries and use that to fine-tune it your need

https://www.sqlbi.com/articles/introducing-the-power-bi-performance-analyzer/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank you for the suggestion. My question is a bit different - how can I perform SQL query to calculate measure value? I.e. select avg(time) from table where date between ('2020-01-01','2020-01-31')?

@martynas , when creating a connection you have the option to give the query Advance, there you can add qyery ?

AdvanceProperty.png

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Yes, that would be possible, but how do I pass the start and end date parameters from slicer in report?

Hi @martynas ,

 

Based on your description, do you want to pass the slicer value to the SQL query statement? Complete the calculation in SQL?

Refer to

power-bi-desktop-query-parameters-part2-dynamic-data-masking-and-query-parameters 

pass-parameters-to-sql-queries 

You can also try to use SSAS to connect live with powerbi.

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.