Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Table transformation to return rows within last 7 days

Green_ Desmond
Contributor
November 20, 2023

I have a simple table where the first field is 'Date' and I enter relevant date values using the calendar control.

Table data.JPG

I want to be able to filter the table to only show rows from the past 7 days. In other words, >= GetDate()-7.

I've tried everything to make this work in a table transformer macro. At best, it returns rows from completely different months. For example, at 20 November, the filter shows rows from 13 to 20 November, but also rows for 13 to 20 October, and September, etc.!

Filtered but wrong months.JPG

I can use a table filter, with a column filter, by date to simply filter on from -7d to today. 

Simple table filter.JPG

But why can't I get this to work in what should be a more flexible table transformer macro?

I've tried this:

SELECT * FROM T1 WHERE FORMATDATE(T1.'Date')
BETWEEN FORMATDATE(DATEADD(DAY, -7, GETDATE())) AND
FORMATDATE(DATEADD(DAY, 0, GETDATE()))

And this:

SELECT * FROM T1 WHERE 
T1.'Date'::Date->toLocaleDateString("en-us", { year:"numeric", month:"short", day:"2-digit"})
BETWEEN DATEADD(w,-1, GETDATE()::Date->toLocaleDateString("en-us", { year:"numeric", month:"short", day:"2-digit"}))
AND GETDATE()::Date->toLocaleDateString("en-us", { year:"numeric", month:"short", day:"2-digit"})

And also many other things besides!

It's a really simple use case. How do I get this to work? 

1 answer

1 accepted

4 votes
Answer accepted
Stiltsoft support
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 20, 2023

Hi @Green_ Desmond ,

Please try the following SQL query:

SELECT * FROM T*
WHERE DATEDIFF(day,'Date',"today") <= 7

The date format in the Settings tab of your Table Transformer macro should correspond your current date format that is "d M yy".

Green_ Desmond
Contributor
November 20, 2023

That's perfect, I looked at DATEDIFF but didn't feel quite right for what I was trying to do.

But it's exactly what I want and works perfectly - thank you!

Like 2 people like this

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events