Forum Discussion

ACSpotlight's avatar
ACSpotlight
Regular Visitor
10 months ago
Solved

Dynamic Measure developement

Hi I am wanting to develop a quite complex solution. The basis is I have a business running off a retail based calendar 4,5,4 week periods etc.  The requirement is to have a slicer that selects a ...
  • johnt75's avatar
    10 months ago

    Firstly, given that you are using a 4,5,4 calendar I would recommend that you use the new time intelligence functions which are calendar based, introduced in the September 2025 update. SQLBI have an excellent article on this new preview feature at https://www.sqlbi.com/articles/introducing-calendar-based-time-intelligence-in-dax/ .

    For the time intelligence calculations, I would create a calculation group with items for the different periods you want to show, and present these options to the user in a slicer.

    For the dynamic date range on the chart axis, create a field parameter which contains the different granularities of date you wish to show - day, week, period. Use this field parameter as the X-axis.

    You will need to add a couple of new columns to the table created for the field parameter, to store the minimum and maximum number of days for which you want to use that granularity.

    Go into the table view and select the field parameter table. You will see the DAX code which creates the table, each row has the name of the column, the table reference and an integer, which is the sort order. After the sort order you need to add 2 new numbers, separated by a comma. The first will be the minimum number of days to show at that granularity, the second is the maximum.

    The minimum for the first entry should be 0. The maximum for the last entry should be BLANK(). For every other entry the minimum value should be the same as the maximum of the previous entry.

    When you have added the new columns, change their names to "Min Days" and "Max Days".

    Create a measure like

    Choose Date Precision = 
    VAR FirstVisibleDate = MIN( 'Date'[Date] )
    VAR LastVisibleDate = MAX( 'Date'[Date] )
    VAR DaysDiff = DATEDIFF( FirstVisibleDate, LastVisibleDate, DAY)
    VAR MinDays = SELECTEDVALUE( 'Date Precision'[Min Days] )
    VAR MaxDays = SELECTEDVALUE( 'Date Precision'[Max Days] )
    VAR Result = IF( MinDays <= DaysDiff && ( ISBLANK( MaxDays ) || MaxDays > DaysDiff ), 1, 0 )
    
    RETURN Result

    Add this measure as a TOPN filter on the field parameter, set to show only the top 1 items.

    Now when you change the number of dates visible through your time intellgence calculation items the granularity of the axis should change dynamically.

  • v-ssriganesh's avatar
    10 months ago

    Hi ACSpotlight,
    Thank you for reaching out to the Microsoft fabric community forum.

    The best solution for your scenario is to use Power BI’s calendar-based time intelligence features, which work natively with retail calendars like 4-5-4 and allow full flexibility on how you group and analyze time periods. This approach supports dynamic slicers, lets you switch between period, week or day views and provides faster performance compared to older methods.

    Make sure your date dimension is set up for your retail calendar and marked as a date table. Leverage the new time intelligence functions these enable dynamic periods and granular axes without complex code, and calculation groups or field parameters make it easy to switch measure logic and visual granularity based on user selection.

    This method will ensure smooth, flexible reporting and optimal performance for your complex time intelligence requirements.

     
    Best regards,
    Ganesh Singamshetty.