Power Bi Dynamic Date Range on X-Axis

Viewed 21

I was attempting to have a dynamic date field that would change from a standard 'weekly' view to a 'monthly' view if the user selects the monthly option. I created a separate stand alone table with just the two options ('Week' & 'Month') and that is used in a slicer. However, it seems you can't (not supported) have dynamic fields in a calculated column as it doesn't change based on what's selected as it should. So I moved to have similar DAX function but in a measure, however, this measure works but relies on my main calendar table so in the end can't be used in any visuals other than tables/pivots if the [Date] column is included. So a little stuck and not sure why it's so complicated to do something seeming so simple.

The below DAX is just an example of a few of the things I tried (Yes I started with Switch functions which end up doing the same thing as below in my used case.)[Selected_DateType] is just a SELECTEDVALUE() function that checks for what is currently selected ('Week' || 'Month').

'VAR date_type =
    IF (
        [Selected_DateType] = "Month",
        Date(YEAR(SELECTEDVALUE('CALENDAR'[Date])),MONTH(SELECTEDVALUE('CALENDAR'[Date])),1),
        Date(YEAR(SELECTEDVALUE('CALENDAR'[Date])),MONTH(SELECTEDVALUE('CALENDAR'[Date])+(7-WEEKDAY(SELECTEDVALUE('CALENDAR'[Date])))),DAY(SELECTEDVALUE('CALENDAR'[Date])+(7-WEEKDAY(SELECTEDVALUE('CALENDAR'[Date])))))
    )

Again, all I'm looking to do is have some sort of column chart that has a dynamic date on the x-axis that dynamically changes from a weekly view to monthly if the slicer is selected. If there is no way to change this then I will just end up using Bookmarks, just didn't want to go that route as it's a pain when needing to add-on or add new items to the dashboard.

1 Answers
Related