Forum Discussion
Filter dates in X axis dynamically in a column chart based on a date slicer selection
Hi Reddy5833 ,
Thanks for reaching out to our community.
After I reviewed your post, I deduce that the crux of the matter is the relationship that exists between the date table and the main table. If you want to keep the relationship, you can modify the measure as follows:
Dynamic Entry Count =
VAR MaxFactDate =
MAX ( Entries[Entry Date] )
VAR SelectedMinDate =
MIN ( 'DateTable'[Date] )
VAR SelectedMaxDate =
MAX ( 'DateTable'[Date] )
VAR DaysRange = [DaysSelected]
RETURN
SWITCH (
TRUE (),
DaysRange <= 4,
CALCULATE (
DISTINCTCOUNT ( 'Entries'[Machine ID] ),
FILTER (
ALL ( 'Entries' ),
Entries[Entry Date] >= MaxFactDate - 9
&& Entries[Entry Date] <= MaxFactDate
)
),
DaysRange > 4
&& DaysRange <= 10,
CALCULATE (
DISTINCTCOUNT ( 'Entries'[Machine ID] ),
FILTER (
ALL ( 'Entries' ),
Entries[Entry Date] >= MaxFactDate - 14
&& Entries[Entry Date] <= MaxFactDate
)
),
DaysRange > 10,
CALCULATE (
DISTINCTCOUNT ( 'Entries'[Machine ID] ),
FILTER (
ALL ( 'Entries' ),
Entries[Entry Date] >= SelectedMinDate
&& Entries[Entry Date] <= SelectedMaxDate
)
)
)
I add ALL function to ignore the fitlering of dates. Hope it helps.
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous, thanks for the reply,
It is still not working, the cart is showing the data for all the dates as we are using 'All' function, but my requiremetn is different: it is as described belwo
For example, let’s say max entry date in my fact table is 09-Sep-2024,
if I choose the date range of 1-Jan-2024 to 4-Jan-2024 (4 days) from slicer, then it should display last 10 days on the x axis of the column chart that means from 31-Aug-2024 to 9-Sep-2024.
similarly if the selected date range is more than 4 days (1-Jan-2024 to 5-Jan-2024) and <= 10 days (1-Jan-2024 to 10-Jan-2024), then we should show last 15 days ( 26-Aug-2024 to 9-Sep-2024) data in the chart.
But if the selected date range is greater than 10 days (1-Jan-2024 to 11-Jan-2024) then show whatever the range selected by user, (show 1-Jan-2024 to 11-Jan-2024 data in the chart)
Anonymous Sorry for the typo
- Anonymous1 year agoNot applicable
Hi Reddy5833 ,
Thanks for your reply. I can understand your needs now based on your new description. Your measures are actually pretty good, I made a simple sample of data and applied your two measures, and it successfully returned the correct results.
See Entry Date data:
Here's what the filter results for different filters.
According to my reasoning, the reason for the error in measure return on your side is because there is a relationship between your Date Table and the Entry Date, please remove it.
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Reddy58331 year agoHelper II
Anonymous Thanks a lot for you efforts, it shows the right count when you put in the card visual, but when I plot the column chart, it it showing as below.
In the above screenshot, I have selected 3 days from the date range slicer, as per my original requirement if I selct <= 4 dasy it should show last 10 days data that means 10 bars on the bar chart, distinct count by each date for 10 days.
below is the expected output (Considering Sep-9 is the max date available in my fact table)