Forum Discussion
Counting values based on two filters with 'Today' variable
Hello all,
I have created the following measure, which nicely returns the number of rows in my table where the 'Current Due Date' is in the past. However, I want to add a second filter to this so that it returns the number of rows where the due date is in the past, but not older than 5 days.
However, DAX won't led me add a second filter. Anyone know how to fix this?
Risks Next 5 Days =
VAR __Today = Today()
RETURN
COUNTROWS(
FILTER(
ALL(Table),Table[Current Due Date] <__Today
)
)
- Anonymous4 years ago
Hi Anonymous ,
Here are the steps you can follow:
1. Create measure.
Rank = var _today=TODAY() return RANKX(FILTER(ALL('Table'),'Table'[Current Due Date]<=_today),CALCULATE(MAX([Current Due Date])),,DESC)Flag = IF( [Rank]>1&& [Rank]<=6,1,0)2. Place [Flag]in Filters, set is=1, apply filter.
3. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
4 Replies
- SykResident Rockstar
Try something like this
Risks Next 5 Days = VAR __Today = today() VAR __Todayminusfive = dateadd(today(),-5,days) RETURN CALCULATE( COUNTROWS('Table') ,DATESBETWEEN(Table[Current Due Date],__Todayminusfive,__Today) ) )- AnonymousNot applicable
Thank you - but this throws up an error: The 'Today()' in the second variable is not allowed because a column is required. If it helps, here is the table:
Site Risk ID Risk Detail Current Due Date Site #1 Risk ID #1 Risk Detail #1 20/11/2022 Site #2 Risk ID #2 Risk Detail #2 25/01/2022 Site #3 Risk ID #3 Risk Detail #3 01/09/2022 Site #4 Risk ID #4 Risk Detail #4 05/09/2022 Site #5 Risk ID #5 Risk Detail #5 08/02/2022 Site #6 Risk ID #6 Risk Detail #6 20/08/2022 Site #7 Risk ID #7 Risk Detail #7 03/10/2022 Site #8 Risk ID #8 Risk Detail #8 06/07/2022 Site #9 Risk ID #9 Risk Detail #9 04/05/2022 Site #10 Risk ID #10 Risk Detail #10 30/03/2022 Site #11 Risk ID #11 Risk Detail #11 11/05/2022 Site #12 Risk ID #12 Risk Detail #12 04/05/2022 Site #13 Risk ID #13 Risk Detail #13 12/05/2022 Site #14 Risk ID #14 Risk Detail #14 24/01/2022 Site #15 Risk ID #15 Risk Detail #15 05/04/2022 Site #16 Risk ID #16 Risk Detail #16 27/03/2022 Site #17 Risk ID #17 Risk Detail #17 09/11/2022 Site #18 Risk ID #18 Risk Detail #18 27/06/2022 Site #19 Risk ID #19 Risk Detail #19 15/09/2022 Site #20 Risk ID #20 Risk Detail #20 20/11/2022 - SykResident Rockstar
That's helpful! In the screenshot I used 150 days because nothing was within 5 days but try this
Measure = SUMX('Table', var datedifference = DATEDIFF('Table'[Current Due Date],TODAY(),DAY) var result = if(datedifference >= 0 && datedifference <= 5,1) return result )
- AnonymousNot applicable
Hi Anonymous ,
Here are the steps you can follow:
1. Create measure.
Rank = var _today=TODAY() return RANKX(FILTER(ALL('Table'),'Table'[Current Due Date]<=_today),CALCULATE(MAX([Current Due Date])),,DESC)Flag = IF( [Rank]>1&& [Rank]<=6,1,0)2. Place [Flag]in Filters, set is=1, apply filter.
3. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly