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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Frequent Visitor

Dynamic Grouping of Dates

Hi community, 
I have a simple table which include only dates (start of the week) and respective percentages. I have already done the dynamic filtering of dates so that if I select any date from the slicer I will get all the dates upto that selected date using the code below. 

Average CTSP =
VAR NumOfDays = -MIN('Sample'[Snapshot Week])
VAR ReferenceDate = MAX ('Sample'[Snapshot Week])
VAR PreviousDates =
       'Previous Week'[Snapshot Week],
VAR Result =
        AVERAGE('Sample'[CTSP %]),
        REMOVEFILTERS ('Sample'[Snapshot Week]),
        KEEPFILTERS ( PreviousDates),
        USERELATIONSHIP ( 'Previous Week'[Snapshot Week], 'Sample'[Snapshot Week])

The output of this is like: I am getting all the dates upto that selected date which is good but I also want to group the dates in 2 weeks period such that I can see only 3 dates (I don't want to group the selected week) and average their average percentage. 

26-11-2023 30%


How can we acheive this. Is there any modfication that we can do in the existing measure itself ? 

Thanks in advance.

Frequent Visitor

Hi team, 
Any solutuon for the problem ?

Frequent Visitor

Thank you so much @v-xinruzhu-msft           




We are almost there but I'am getting something different than I expected. On the top chart I'am having raw data and below is the modified one. So when selecting 07-01-2024, I think it's not grouping but filtering it maybe
So the expected output looking for is: 

26-11-2023    50%
03-12-2023   55%
24-12-2023  67.5%
07-01-2024   40%

We can see it grouped in 2 weeks bin and taken the average. 

Hi @JunedS 

I don't understand the logic of the grouping, Based on your original output, don't you want to implement a return date every 14 days?


Best Regards!

Yolo Zhu

Hi @v-xinruzhu-msft 
Let me clarify the logic behind the grouping. Instead of setting a return date every 14 days from the selected date, the idea is to group the dates into bins of two weeks each based on the chosen date in the slicer. This means we're organizing the dates into two-week intervals, but we're not directly grouping the selected date itself.

Imagine the user selects a date in the slicer, and let's use January 7th, 2024, as an example. With the grouping logic based on two-week bins, it might look like this:

  • Group 1: January 7th 2024 (Selected date) 40%
  • Group 2: December 24th 2023 - December 31st 2023 , the average CTSP 67.5%
  • Group 3: December 3rd 2023 - December 17th 2023, the average CTSP 55%
  • Group 4: 26th Nov 2023, this is the last one left out so only one in the group with CTSP 50%

    In this case, the selected date (January 7th) falls within its own group, and the surrounding two-week periods are organized accordingly. 

Community Support
Community Support



Hi @JunedS 

You can try the following measure.

Average CTSP =
VAR NumOfDays =
    - MIN ( 'Sample'[Snapshot Week] )
VAR ReferenceDate =
    MAXX ( ALLSELECTED ( 'Sample' ), [Snapshot Week] )
VAR PreviousMinDate =
        MIN ( 'Previous Week'[Snapshot Week] ),
        DATESINPERIOD ( 'Previous Week'[Snapshot Week], ReferenceDate, NumOfDays, DAY )
VAR Generatedate =
    GENERATESERIES ( PreviousMinDate, ReferenceDate, 14 )
VAR Result =
        AVERAGE ( 'Sample'[CTSP %] ),
        REMOVEFILTERS ( 'Sample'[Snapshot Week] ),
        FILTER ( 'Previous Week', [Snapshot Week] IN Generatedate ),
        USERELATIONSHIP ( 'Previous Week'[Snapshot Week], 'Sample'[Snapshot Week] )

Best Regards!

Yolo Zhu

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

Helpful resources

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.


Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.


Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors