Forum Discussion
Date filter, unexpected results
Hello I am using a simple date filter expression to sum values below a date picked by a user.
The dates are supplied by a date table which is related to the dates in the value table. The values sum fine, until a user picks a date with no date in the value table and the summed value ends up as the first value in the data table.
total_tonnes_transfer = calculate(
qry_Sous_Tirage_Transfer[transfer_tonnes],
filter(all(qry_Sous_tirage),
qry_Sous_tirage[Date_Transfert] <= Date([selected_Year],[Selected_month_2],[Selected_Day_nb2])
&& qry_Sous_tirage[Date_Transfert]<= max(qry_Sous_Tirage_Transfer[Date_Transfert])
)
)
e.g.
Tonnes Selected date
21521 2020-06-02
Tonnes Selected Date
336 2020-06-03
Any ideas?
Thanks
Hi Peter_au ,
Just add a filter condition like this and check the "show items with no data" option:
total_tonnes_transfer = calculate( SUM('Table'[Tonnes_Blast_id]), filter(all('Table'), 'Table'[Date_Transfert] <= SELECTEDVALUE('Table 2'[Date]) &&SELECTEDVALUE('Table 2'[Date]) in VALUES('Table'[Date_Transfert]) ) )Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 Replies
- AllisonKennedy
Community Champion
I'm a bit confused by your formula - is that a MEASURE?
Where is the SUM part of it? Do you have a DimDate table?
total_tonnes_transfer = SUMX(filter(all(qry_Sous_tirage),
qry_Sous_tirage[Date_Transfert] <= Date([selected_Year],[Selected_month_2],[Selected_Day_nb2]),
qry_Sous_Tirage_Transfer[transfer_tonnes])
But without seeing your calculations for Selected Year, Selected Month, etc I can't be sure if that will work. I think using a DimDate table would be better, and having user filter for SELECTEDVALUE(DimDate[Date])- parry2k
Super User
Peter_au Not sure what you are trying to achieve. Best way is to paste sample data with the expected output. Don't just put the measure without sharing the data model and what you want to achieve. Read this post to get your answer quickly.
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490- Peter_au
Helper I
Data:
Date_Transfert Tonnes_Blast_id 2020-06-18 480 2020-06-19 1248 2020-06-19 336 2020-06-19 288 2020-06-19 240 2020-06-19 336 2020-06-19 480 2020-06-20 144 2020-06-20 288 2020-06-20 480 2020-06-21 384 2020-06-21 48 2020-06-21 960 2020-06-21 720 2020-06-22 48 2020-06-22 528 2020-06-22 432 2020-06-23 240 2020-06-23 384 2020-06-23 384 2020-06-23 96 2020-06-24 48 2020-06-24 1392 2020-06-24 96 2020-06-24 384 2020-06-24 480 2020-06-25 288 2020-06-25 480 2020-06-25 912 2020-06-25 48 2020-06-25 288 2020-06-25 144 2020-06-26 336 2020-06-26 816 2020-06-26 96 2020-06-28 288 2020-06-28 288 2020-06-28 2160 2020-06-28 48 2020-06-28 1200 2020-06-29 480 2020-06-29 288 2020-06-30 240 2020-06-30 240 2020-06-30 336 2020-07-01 480 2020-07-01 336 2020-07-01 288 2020-07-02 288 2020-07-02 288 2020-07-02 48 2020-07-02 480 2020-07-03 384 2020-07-03 288 2020-07-03 144 Measure:
total_tonnes_transfer = calculate(qry_Sous_Tirage_Transfer[transfer_tonnes],filter(all(qry_Sous_Tirage_Transfer),qry_Sous_Tirage_Transfer[Date_Transfert] <= Date([selected_Year],[Selected_month_2],[Selected_Day_nb2])&& qry_Sous_Tirage_Transfer[Date_Transfert]<= max(qry_Sous_Tirage_Transfer[Date_Transfert])))Dates:Selected_date = format(DATEVALUE([selected_Year] & "-" & [Selected_Month_Abv] & "-" & [Selected_Day_nb2]),"YYYY-MM-DD")Selected_Day_nb2 = SELECTEDVALUE(date_Tbl[Day_nmb_2])Selected_month_2 = month([Selected_date])Selected_Month_Abv = selectedvalue(date_Tbl[Month_Abv])selected_Year = SELECTEDVALUE((date_Tbl[Year]))Expected result:total_tonnes_transfer Selected_date 10944 2020-06-24 or
total_tonnes_transfer Selected_date 18336 2020-06-28 Unexpected result
total_tonnes_transfer Selected_date 2020-06-27 Here is the information that was requested.If the date is not it the data, there is no sum.Thanks