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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Astargle95
Frequent Visitor

GPS Segmenting

Hello. I am importing a DB2 table into power bi with vehicle gps information. What I am trying to do is segment out the gps points. I would like to create a column in Power Bi so that everytime 0 comes up in the miles per hour column, it creates a new segment so then I can add that column to a slicer and see the routes for starting and stopping. But if there are multiple 0's in a row like segment 1, I would need those to be in the same segment until the vehicle moves and the next 0 would start the following segment. In the photo, for segment 1, I would like all of those records to have a "1" value in the segment column and so on. Not every day starts at 0mph either. For the example below, the first record of that day is 2.48mph. I would like to just ignore those first three records and start my segmenting at the first 0mph. Thanks

 

Astargle95_0-1659365409093.png

 

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

Hi @Astargle95 ,

According to your description, here's my solution.

Create three calculated columns.

0_Date =
MAXX (
    FILTER (
        'Table',
        'Table'[Date] <= EARLIER ( 'Table'[Date] )
            && 'Table'[Rate] = 0
    ),
    'Table'[Date]
)
0_DateNew =
IF (
    COUNTROWS ( FILTER ( 'Table', 'Table'[0_Date] = EARLIER ( 'Table'[0_Date] ) ) ) = 1,
    MINX (
        FILTER (
            'Table',
            'Table'[Date] > EARLIER ( 'Table'[Date] )
                && COUNTROWS ( FILTER ( 'Table', 'Table'[0_Date] = EARLIER ( 'Table'[0_Date] ) ) ) <> 1
        ),
        'Table'[Date]
    ),
    'Table'[0_Date]
)
Segment =
VAR _Rank =
    IF (
        'Table'[Date]
            >= MINX ( FILTER ( 'Table', 'Table'[Rate] = 0 ), 'Table'[Date] ),
        "Segment" & " "
            & RANKX (
                'Table',
                IF (
                    MAXX (
                        FILTER (
                            'Table',
                            'Table'[Date] <= EARLIER ( 'Table'[Date] )
                                && 'Table'[Rate] = 0
                        ),
                        'Table'[Date]
                    )
                        = BLANK (),
                    MAXX ( 'Table', 'Table'[Date] ),
                    [0_DateNew]
                ),
                ,
                ASC,
                DENSE
            ),
        BLANK ()
    )
RETURN
    _Rank

Get the correct result.

vkalyjmsft_0-1659584426659.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

1 REPLY 1
v-yanjiang-msft
Community Support
Community Support

Hi @Astargle95 ,

According to your description, here's my solution.

Create three calculated columns.

0_Date =
MAXX (
    FILTER (
        'Table',
        'Table'[Date] <= EARLIER ( 'Table'[Date] )
            && 'Table'[Rate] = 0
    ),
    'Table'[Date]
)
0_DateNew =
IF (
    COUNTROWS ( FILTER ( 'Table', 'Table'[0_Date] = EARLIER ( 'Table'[0_Date] ) ) ) = 1,
    MINX (
        FILTER (
            'Table',
            'Table'[Date] > EARLIER ( 'Table'[Date] )
                && COUNTROWS ( FILTER ( 'Table', 'Table'[0_Date] = EARLIER ( 'Table'[0_Date] ) ) ) <> 1
        ),
        'Table'[Date]
    ),
    'Table'[0_Date]
)
Segment =
VAR _Rank =
    IF (
        'Table'[Date]
            >= MINX ( FILTER ( 'Table', 'Table'[Rate] = 0 ), 'Table'[Date] ),
        "Segment" & " "
            & RANKX (
                'Table',
                IF (
                    MAXX (
                        FILTER (
                            'Table',
                            'Table'[Date] <= EARLIER ( 'Table'[Date] )
                                && 'Table'[Rate] = 0
                        ),
                        'Table'[Date]
                    )
                        = BLANK (),
                    MAXX ( 'Table', 'Table'[Date] ),
                    [0_DateNew]
                ),
                ,
                ASC,
                DENSE
            ),
        BLANK ()
    )
RETURN
    _Rank

Get the correct result.

vkalyjmsft_0-1659584426659.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.