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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
aTChris
Resolver I
Resolver I

Problems with GroupKind.Local

I'm working with a dataset that has events recorded which I need to group when an attribute changes.

I used https://blog.crossjoin.co.uk/2014/01/03/aggregating-by-local-groups-in-power-query/

The issue I have is the End Datetime and the next rows Start DateTime has a gap.

 

Ideally, I need the End DateTime of the previous row to be 1 second less than the Start DateTime.

 

Screenshot 2020-10-02 at 18.56.59.png

 

let
    Source = Excel.Workbook(File.Contents("C:/Data.xlsx"), null, true),
    Sheet3_Sheet = Source{[Item="Sheet3",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet3_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Column1", Int64.Type}, {"moved", Int64.Type}, {"event_at", type datetime}, {"temp", type number}, {"co2", Int64.Type}, {"hum", type number}, {"mac", type text}, {"sn", type text}, {"message_type", Int64.Type}, {"building_id", Int64.Type}, {"timezone", type text}, {"floor_id", Int64.Type}, {"group_types", type text}, {"spaces", type text}, {"groups", type text}, {"space_types", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([message_type] = 2)),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"sn"}, {{"Count", each _, type table [Column1=nullable number, moved=nullable number, event_at=nullable datetime, temp=nullable number, co2=nullable number, hum=nullable number, mac=nullable text, sn=nullable text, message_type=nullable number, building_id=nullable number, timezone=nullable text, floor_id=nullable number, group_types=nullable text, spaces=nullable text, groups=nullable text, space_types=nullable text]}}),
    #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"moved", "event_at", "message_type", "building_id", "floor_id", "group_types", "spaces", "groups", "space_types"}, {"Count.moved", "Count.event_at", "Count.message_type", "Count.building_id", "Count.floor_id", "Count.group_types", "Count.spaces", "Count.groups", "Count.space_types"}),
    #"Grouped Rows1" = Table.Group(#"Expanded Count", {"sn", "Count.moved"}, {{"Start", each List.Min([Count.event_at]), type nullable datetime}, {"End", each List.Max([Count.event_at]), type nullable datetime}, {"Building.ID", each List.Min([Count.building_id]), type nullable number}, {"Spaces", each List.Min([Count.spaces]), type nullable text}, {"Groups", each List.Min([Count.groups]), type nullable text}, {"SpaceType", each List.Min([Count.space_types]), type nullable text}}, GroupKind.Local)
in
    #"Grouped Rows1"

 

Any ideas? 

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

Hello @aTChris ,

You can use DAX to accomplish this.

1. Add an [Index] column.

2. Create a calculated column.

__start = 
VAR x = 
CALCULATE(
    MAX(Sheet6[end]),
    FILTER(
        Sheet6,
        Sheet6[Index] = EARLIER(Sheet6[Index]) - 1
    )
)
RETURN
IF(
    x = BLANK(),
    [start],
    x + 1/86400
    
)

v-lionel-msft_0-1601889270523.png

Best regards
Lionel Chen

If this post helps,then consider Accepting it as the solution to help other members find it faster.

View solution in original post

1 REPLY 1
v-lionel-msft
Community Support
Community Support

Hello @aTChris ,

You can use DAX to accomplish this.

1. Add an [Index] column.

2. Create a calculated column.

__start = 
VAR x = 
CALCULATE(
    MAX(Sheet6[end]),
    FILTER(
        Sheet6,
        Sheet6[Index] = EARLIER(Sheet6[Index]) - 1
    )
)
RETURN
IF(
    x = BLANK(),
    [start],
    x + 1/86400
    
)

v-lionel-msft_0-1601889270523.png

Best regards
Lionel Chen

If this post helps,then consider Accepting it as the solution to help other members find it faster.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.