Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

dynamic data range

I need a visual to return a range of periods (a month-like time window) according to a selection in a slicer.  The range will always be 3 periods, and it will begin with the period selected in the slicer.  So, for example, if period "Per3" is selected, then the visual needs to display only periods Per3, Per4, and Per5; similarly, if period "Per6" is selected, then the visual needs to display only periods Per6, Per7, and Per8.  How can I achieve this?  I have tried to follow the solution method below, but it's not working for me.  I suspect that it has something to do with the fact that I'm using a dimension model (not a completely denormalized model) and the fact that I have already calculated the ending period to use in the time range.

 https://radacad.com/dynamic-date-range-from-slicer

 

Below is my data:

 

fact table:

DateKeyUnitsSold
11
25
32
410
53
64
72
87
97
104
113
126
1311
146
154
162
179
184
194
205

 

dimension date table:

DateKeyPeriodPeriodLabelPeriodPlus3PeriodPlus3Label
11Per13Per3
21Per13Per3
32Per24Per4
42Per24Per4
53Per35Per5
63Per35Per5
74Per46Per6
84Per46Per6
95Per57Per7
105Per57Per7
116Per68Per8
126Per68Per8
137Per79Per9
147Per79Per9
158Per810Per10
168Per810Per10
179Per9  
189Per9  
1910Per10  
2010Per10  

 

Here is my data model:

data model.png

 

As you can see, I copied the DimensionDate table as the DimensionDateSlicer table and left it disconnected from the main data model (which is necessary for the solution method).  (I also like to put all of my measures per model on a separate empty table, which is the DummyForMeasures table.)

 

To make sure that the sorting is correct, below is my sorting (on both the DimensionDate and DimensionDateSlicer tables):

sorting.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Here are my measure definitions:

 

Dummy measure for filter = 
var DimensionDatePeriod = MIN('DimensionDate'[Period])
var SlicerSelection = MIN('DimensionDateSlicer'[Period])
var DimensionDatePeriodPlus3 = MIN('DimensionDate'[PeriodPlus3])

RETURN
    IF(
        (DimensionDatePeriod >= SlicerSelection)
        && (DimensionDatePeriod <= DimensionDatePeriodPlus3)
        ,1 --arbitrary indicator for TRUE
    )

 

 

Total Units Sold = SUM('Fact'[UnitsSold])

 

 

Here is the visual configuration for my slicer.  (As you can see, PeriodLabel here comes from DimensionDateSlicer, not DimensionDate.)

slicer properties.png

 

Here is the configuration for my clustered column chart.  (As you can see, PeriodLabel here comes from DimensionDate, not DimensionDateSlicer, which is necessary for the solution method.  And, [Dummy measure for filter] is set to 1 on the filter pane for this visual.)

column chart properties.png

 

As you can see with 'Per3' selected, I am incorrectly displaying 6 periods.  It should display only 3 periods.  What am I doing wrong, and how do I resolve?

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Try this:

Dummy measure for filter =
VAR DimensionDatePeriod =
    MIN ( 'DimensionDate'[Period] )
VAR SlicerSelection =
    MIN ( 'DimensionDateSlicer'[Period] )
VAR DimensionDatePeriodPlus3 =
    MIN ( 'DimensionDateSlicer'[PeriodPlus3] ) ------------Changed.
RETURN
    IF (
        ISBLANK ( SELECTEDVALUE ( DimensionDateSlicer[Period] ) ), ----------Added.
        1,
        IF (
            ( DimensionDatePeriod >= SlicerSelection )
                && ( DimensionDatePeriod <= DimensionDatePeriodPlus3 ),
            1
        )
    )

dynamic.gif

 

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

I did not get you completely. But something like this should work for you

 

Measure =
var _minPrd = maxx(filter('dimension date','dimension date'[Period label]
					=(maxx('dimension date',allselected('dimension date'[Period label])))),'dimension date'[Period])


var _maxPrd = _minPrd+3

return
calculate(sum(Fact[Unit Sold]),filter(all('dimension date'),'dimension date'[Period]>=_minPrd && 'dimension date'[Period]<=_maxPrd))

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Proud to be a Datanaut Connect on Linkedin

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak 

The data model that I posted is a simplified version of my actual data model.  In my actual data model, I can't simply add 3 to Period to obtain PeriodPlus3.  In my actual data model, my Period values are like 20062007.01 (to represent the first period of fiscal year 2006-2007) and 20192020.12 (to represent the last period of fiscal year 2019-2020).  That is why my Dimension Date table includes columns for PeriodPlus3 / PeriodPlus3Label.  In other words, I've already done the work (in the creation of the Dimension Date table ) to create the PeriodPlus3 value for every Period value.  (It doesn't need to -- and shouldn't -- be done in DAX.)  Is there a way to set _maxPrd from the PeriodPlus3 value already in the table?  (I think this is one of the things that makes my data model unique, as every solution I've seen for this problem always computes the _maxPrd variable through math, rather than fetching it from a table.)

Icey
Community Support
Community Support

Hi @Anonymous ,

 

Try this:

Dummy measure for filter =
VAR DimensionDatePeriod =
    MIN ( 'DimensionDate'[Period] )
VAR SlicerSelection =
    MIN ( 'DimensionDateSlicer'[Period] )
VAR DimensionDatePeriodPlus3 =
    MIN ( 'DimensionDateSlicer'[PeriodPlus3] ) ------------Changed.
RETURN
    IF (
        ISBLANK ( SELECTEDVALUE ( DimensionDateSlicer[Period] ) ), ----------Added.
        1,
        IF (
            ( DimensionDatePeriod >= SlicerSelection )
                && ( DimensionDatePeriod <= DimensionDatePeriodPlus3 ),
            1
        )
    )

dynamic.gif

 

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Community Champion
Community Champion

Wait, why does Per6 display 6,7 and 10 or is that a typo?

 

If your slicer is connected to your main table? You may need a disconnected table for you slicer.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler 

You're correct.  It's a typo.  I just corrected my post.  Sorry about that.

 

As you can see in my data model picture, the field for my slicer comes from a copy of my Dimension Date table, which is disconnected from my data model.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.