Forum Discussion

samotfrt's avatar
samotfrt
Frequent Visitor
2 years ago
Solved

Sum values if date is between two dates and other filter

I have the following tables 

 

 

user_list

media_iduser_idstart_datefinish_datemin_day
1101/01/202202/01/20238.2
3131/12/202201/01/202345.0
2203/01/202301/02/20242.5

 

media

media_idtitleformatnumber_epep_duration
1Series ASeries6050
2Series BSeries2050
3Movie AMovie190

 

 

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

Datetotal_hours
30/12/20238.2
31/12/202353.2
01/01/202353.2
02/01/20238.2
03/01/20232.5

 

 

However when I add that column to a line chart it is unaffect by slicer like "media format" and the values are the same for all the users.
 
I presume I have to use a measure instead but i can't make it work properly. How would you approach this?
 
 
 
PS: I couldn't format the table so i added an image as well
  • Anonymous's avatar
    Anonymous
    2 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 Xu

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

1 Reply

  • Anonymous's avatar
    Anonymous
    Not 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 Xu

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.