Forum Discussion
Filtering twice the same field at different dates
Hello everyone ,
New user here so don't hesitate to tell me if I'm doing something wrong.
So I've got two tables that are a Calendar and a Sales table.
Calendar is like so :
| Date | Same_day_another_year |
| 27/04/2022 | 29/04/2020 |
| 26/04/2022 | 28/04/2020 |
Where same_day_another_year is the same day of the same week but another year that i can filter.
Sales is like so :
| Date | Shop_number | Shop_open | turnover |
| 27/04/2022 | 1 | 1 | 10 |
| 27/04/2022 | 2 | 1 | 30 |
| … | … | … | … |
| 29/04/2020 | 1 | 1 | 30 |
| 29/04/2020 | 2 | 0 | 90 |
Where I have the sum of turnover for each shop each day and an indicator of if the shop was open
Sales and Calendar are linked on the date.
Now, I am trying to get the total turnover of each day and its equivalent another year ONLY for the shops that were open on both dates.
For exemple here that would give me :
| Date | Same_day_another_year | SUM(turnover) 2022 | SUM(turnover) 2020 |
| 27/04/2022 | 29/04/2020 | 10 | 30 |
Because only the shop 1 was open at Date and Same_day_another_year
I have tried a lot of things but none seemed to work.
Does anyone have an idea on how I could proceed ?
Thanks in advance !
4 Replies
- danextianSuper User
Hi KC_user ,
You can create more than one relationship between two tables - one is an active relationship and the others are inactive ones which can be invoked by using USERELATIONSHIP function. Try this measure below:
Turnover - same day another year = CALCULATE ( SUM ( Sales[turnover] ), USERELATIONSHIP ( 'Calendar'[Same_day_another_year], Sales[Date] ) )This is how the two tables relate to each other:
Active Relationship - Calendar[Date] > Sales[Date]
Inactive Relationship - Calendar[Same_day_another_year] > Sales[Date] - KC_userRegular Visitor
Thank you for your answer, I didn't know about that !
However I have no problem calculating the turnover for the previous date.
My true problem is calculating the turnover ONLY if the shop is open at the recent date AND at the previous date.- KC_userRegular Visitor
Hello danextian ,
Thanks again for the answer.
I understand your answer, however what you display gives the sum of turnover for each shop.
Where as i need the total turnover of the day only including shops that are were open on both dates.Let me give you another more detailed example :
If my sales table is like so :
Date Shop_number Shop_open turnover 27/04/2022 1 1 10 27/04/2022 2 1 30 27/04/2022 3 0 40 27/04/2022 4 1 20 … 29/04/2020 1 1 50 29/04/2020 2 0 15 29/04/2020 3 1 25 29/04/2020 4 1 60
Then i want the result to be :Date Same_day_another_year Turnover 2022 Turnover 2020 27/04/2022 29/04/2020 30 110 Thanks !