Help Needed with Weekly Data Query Starting from Monday

Hi team,

I’m working on a dashboard and need data for the past 20 weeks, with each week starting on Monday.

When I run my query, it correctly pulls data for the past 14 weeks, starting on Monday, but the day get changed if I change the number from 14 to any other number.

Here’s the query I’m using:

Bdate >= DATEADD(week, -14, DATEADD(day, -(DATEPART(weekday, CURRENT_DATE) - 1), CURRENT_DATE))

Could anyone suggest a way to adjust this query or another way so it can fetch data for a different number of weeks, starting from Monday?

Thanks!

Hi @cijod
can you share a sample what data you have and what output you expect?
Do you like to use today date and go 20 weeks back? So today it is week 43, go back 20 week, will be week 23, week start will lead to data since 3 June?
BR

Hi @ErikG,
Yes, exactly. Thats the output that I expect. :slight_smile:

You are using PostgreSQL?

Hey @ErikG,
Sorry, I didnt see the message.
I am new to this, and we use SPICE in Amazon.

But what is the database before? because the functions you are using arent QuickSight functions. So it is within your SQL query, right?

Yes. Currently, I’m trying make changes in the SQL query. Its MySQL, I guess.
I add the query here in Quicksight to import the data.
image

Hey @ErikG,
Got the solution.
DATE_TRUNC(‘w’, CURRENT_DATE) - 140.

By using DATE_TRUNC, we can get the data starting from Monday. :slight_smile: