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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
mitja
Frequent Visitor

Group and sum, by date range

Hello.

 

Not sure what all i tryed, but nothing is working.  the problem is that i wish to group "date" +5 days and sum "count"

 

table

2022-06-16 12_52_55-Untitled - Power Query Editor.png

 

 

 

 

 

 

 

 

 

wished Result:

dateNumCount
11.4.2022P01057156
21.4.20223055 77251 06039
3.5.2022P010571560
9.5.2022 - 10.5.2022P010571248
11.5.20223055 772351 06030
16.5.20223055 77278 06028
20.5.2022 - 25.5.2022P01057690

1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @mitja,

 

You can try this solution.

1 Create a Calculated column

Group =
VAR prevDate =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[NUm] ),
            'Table'[date] < EARLIER ( 'Table'[date] )
        )
    )
VAR nextDate =
    CALCULATE (
        MIN ( 'Table'[date] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[NUm] ),
            'Table'[date] > EARLIER ( 'Table'[date] )
        )
    )
VAR prevDiff =
    DATEDIFF ( prevDate, 'Table'[date], DAY )
VAR nextDiff =
    DATEDIFF ( 'Table'[date], nextDate, DAY )
RETURN
    IF (
        prevDiff <= 5
            && NOT ( ISBLANK ( prevDate ) ),
        prevDate & "-" & 'Table'[date],
        IF (
            nextDiff <= 5
                && NOT ( ISBLANK ( nextDate ) ),
            'Table'[date] & "-" & nextDate,
            'Table'[date] & ""
        )
    )

 

2 Create a Table visual like this

vcazhengmsft_0-1655719625130.png

 

Also, attached the pbix file as reference.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let me know. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

View solution in original post

3 REPLIES 3
mitja
Frequent Visitor

thank you

v-cazheng-msft
Community Support
Community Support

Hi @mitja,

 

You can try this solution.

1 Create a Calculated column

Group =
VAR prevDate =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[NUm] ),
            'Table'[date] < EARLIER ( 'Table'[date] )
        )
    )
VAR nextDate =
    CALCULATE (
        MIN ( 'Table'[date] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[NUm] ),
            'Table'[date] > EARLIER ( 'Table'[date] )
        )
    )
VAR prevDiff =
    DATEDIFF ( prevDate, 'Table'[date], DAY )
VAR nextDiff =
    DATEDIFF ( 'Table'[date], nextDate, DAY )
RETURN
    IF (
        prevDiff <= 5
            && NOT ( ISBLANK ( prevDate ) ),
        prevDate & "-" & 'Table'[date],
        IF (
            nextDiff <= 5
                && NOT ( ISBLANK ( nextDate ) ),
            'Table'[date] & "-" & nextDate,
            'Table'[date] & ""
        )
    )

 

2 Create a Table visual like this

vcazhengmsft_0-1655719625130.png

 

Also, attached the pbix file as reference.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let me know. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

rohit_singh
Solution Sage
Solution Sage

Hi @mitja ,

I'm not sure I understand your requirement correctly. Could you please explain what you mean by group "date" +5 days ? or what exactly you're trying to achieve?


Kind regards,

Rohit

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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