Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Table transformation to return rows within last 7 days

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.
Nov 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".

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 # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events