Forum Discussion
Sum values if date is between two dates and other filter
I have the following tables
user_list
| media_id | user_id | start_date | finish_date | min_day |
| 1 | 1 | 01/01/2022 | 02/01/2023 | 8.2 |
| 3 | 1 | 31/12/2022 | 01/01/2023 | 45.0 |
| 2 | 2 | 03/01/2023 | 01/02/2024 | 2.5 |
media
| media_id | title | format | number_ep | ep_duration |
| 1 | Series A | Series | 60 | 50 |
| 2 | Series B | Series | 20 | 50 |
| 3 | Movie A | Movie | 1 | 90 |
My goal is make a graph of the time spend by user watching shows throughout the years, so I though of adding the value of "min_day" from the table "user_list" to the calendar table with
total_hours = CALCULATE(SUM('user_list'[min_day]),FILTER('user_list','user_list'[finish]>='Calendar'[Date]&&'user_list'[start]<='Calendar'[Date]))/60
and get the following
| Date | total_hours |
| 30/12/2023 | 8.2 |
| 31/12/2023 | 53.2 |
| 01/01/2023 | 53.2 |
| 02/01/2023 | 8.2 |
| 03/01/2023 | 2.5 |
- Anonymous2 years ago
Hi samotfrt
There are some errors in your data, please check them yourself.
Here is the test after I changed the data:total_hours = CALCULATE(SUM(user_list[min_day]), FILTER(user_list, [finish_date] >= SELECTEDVALUE('Calendar'[Date]) && 'user_list'[start_date] <= SELECTEDVALUE('Calendar'[Date])))Output:
Is this the result you expect?
Best Regards,
Yulia XuIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
1 Reply
- AnonymousNot applicable
Hi samotfrt
There are some errors in your data, please check them yourself.
Here is the test after I changed the data:total_hours = CALCULATE(SUM(user_list[min_day]), FILTER(user_list, [finish_date] >= SELECTEDVALUE('Calendar'[Date]) && 'user_list'[start_date] <= SELECTEDVALUE('Calendar'[Date])))Output:
Is this the result you expect?
Best Regards,
Yulia XuIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.