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.
Hi,
I am building a query by connecting to a SQL Server Table. To avoid having all the rows I have done a custom SQL Statement to filter while connceting to SQL server as following.
select [$Table].[CreatedDate] as [CreatedDate], [$Table].[Site ID] as [Site ID] from [dbo].[vw_xxxxxxx] as [$Table] WHERE ([CreatedDate] >= N'2016-08-20 00:00:00')
Now whenever I run this query I need to see all the rows WHERE ([CreatedDate] >=(Today) - (2 years).
So if I run it today (08/20/2018), I need to see the rows with Created Date values from 08/20/2016. If I run it tomorrow (08/21/2018), I need to see the rows with Created Date values from 08/21/2016.
Is there any way to dynamically pass on this criteria to SQL statement.
Appreciate any help.
Thanks
Solved! Go to Solution.
Hi @smpa01,
Since this is a direct SQL Statement, you should be able to directly use GETDATE() function as in case of SQL Server.
Did you try something like this
select [$Table].[CreatedDate] as [CreatedDate], [$Table].[Site ID] as [Site ID] from [dbo].[vw_xxxxxxx] as [$Table] WHERE ([CreatedDate] between getdate() and CAST((CAST(YEAR(getdate())-2 as VARCHAR(4))+'-'+CAST(MONTH(getdate()) as VARCHAR(2))+'-'+CAST(DAY(getdate()) as VARCHAR(2))) as DateTime)
Hi @smpa01,
Since this is a direct SQL Statement, you should be able to directly use GETDATE() function as in case of SQL Server.
Did you try something like this
select [$Table].[CreatedDate] as [CreatedDate], [$Table].[Site ID] as [Site ID] from [dbo].[vw_xxxxxxx] as [$Table] WHERE ([CreatedDate] between getdate() and CAST((CAST(YEAR(getdate())-2 as VARCHAR(4))+'-'+CAST(MONTH(getdate()) as VARCHAR(2))+'-'+CAST(DAY(getdate()) as VARCHAR(2))) as DateTime)
Thanks @Thejeswar it worked. You saved me. Thanks mate.
This is what I have used and it did the trick
select [$Table].[CreatedDate] as [CreatedDate] from [dbo].[vw_xxxx] as [$Table] WHERE [CreatedDate] >= CAST((CAST(YEAR(getdate())-2 as VARCHAR(4))+'-'+CAST(MONTH(getdate()) as VARCHAR(2))+'-'+CAST(DAY(getdate()) as VARCHAR(2))) as DateTime)
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
94 | |
81 | |
66 | |
58 |
User | Count |
---|---|
150 | |
119 | |
104 | |
87 | |
67 |