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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
ApurvaKhatri
Helper III
Helper III

Convert SQL statement to Power bI

I need to convert this query in sql to power bi

 


  select sum([lMoney) FROM Money
  where (fromdate between '2017-09-02' and'2017-09-30') and (todate between '2017-09-08' and '2017-09-29' )

 

Is It possible ?

 

 

I have two columns to date ,from date  I need to calculate monthly data (sum[money])  i.e Sept 2017 based on single date column but filtered on from date 2017-09-01 and to date 2017-09-30. How do i acheive that?

 

 

 

8 REPLIES 8
BILASolution
Solution Specialist
Solution Specialist

Hi @ApurvaKhatri

 

I don't understand much, but I hope this script helps. --> Query

 

First, you need to attach AdventureWorks DW. --> AdventureWorksDW

 

Then you can adapt to your case. (At the end, whenever you've created the view, use it in power bi)

mow700
Resolver I
Resolver I

Check out the CALCULATE() function in the DAX reference:

https://msdn.microsoft.com/en-us/library/ee634825.aspx

 

Essentially you would build something like this:

 

New Measure = CALCULATE(SUM([Money]), DATESBETWEEN([Fromdate],"2017-09-01","2017-09-30"), DATESBETWEEN([Todate],"2017-09-08", "2017-09-29"))

 

I need the sum of money for every month  from firstdate - from date to lastdate (todate) of month.

for e.g Sept 1 to sept 30 but i need to select dates based on from date and to date column resp.

 

I need to have data from every month, so I need to generialize it

Easy to do, just update the filters in your calculate statement for your scenario.  These filters don't have to be hard coded, in fact I almost always calculate these.  How would you do this in your original T-SQL statement?  DAX can likely emulate your approach. 

For example, check out the DAX filter functions like ALLSELECTED():

https://msdn.microsoft.com/en-us/library/ee634807.aspx

 

Please can you help me with the code that what should I replace with in place of dates.

 

I am unable to do it

Your original TSQL statement doesn't give me enough details to help here, the example is using hard coded dates.  DAX can certainly help you determine these dates, but you'll need to provide additional details.  

I am unable to do it.

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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