Below is my table and has id's, dates columns
ID Date
1 2017-06-11
2 2017-06-11
3 2017-06-04
1 2017-06-04
4 2017-06-04
5 2017-06-04
6 2017-05-28
5 2017-06-04
2017-06-11 is this week beginning date and 2017-06-04 is last week beginning date. I want to create a flag where an Id exists in previous week and not in this week as 1.
for example, ID 4 is present in previous week and not in this week.similarly ID 6 is present in 2017-05-28 and not in 2017-06-04. When I query/analyse my data in this week then my data should look like
ID Date flag
1 2017-06-11 0
2 2017-06-11 0
3 2017-06-04 0
1 2017-06-04 0
4 2017-06-04 1
5 2017-06-04 0
Similarly when I analyse my data for previous week,
ID Date flag
3 2017-06-04 0
1 2017-06-04 0
4 2017-06-04 0
5 2017-06-04 0
6 2017-05-28 1
5 2017-06-04 0
I tried with Left join to check Id's present in current date and not in previous date , however i get inaccurate data because this has to be dynamic. When I query each week, I have to compare this week and previous week only and when I query last week, I have to get last week and 2017-05-28 data only.
Then I give filter in tableau to select the date and display the result.
Can anyone help me how to solve this problem?