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 August 31st. Request your voucher.

Reply
IghorLima26
Frequent Visitor

Categorize based on rows with the same values ​​and in sequence

Hi, 

I would like to create a column (RESULT) with the condition that if the category is repeated sequentially (ID) it returns the first ID. 

For example:

IghorLima26_0-1698168204392.png

 

1 ACCEPTED SOLUTION

Hi,

Thank you for your clarification.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1698260224181.png

 

 

Result First ID CC =
VAR _currentid = Data[ID]
VAR _condition =
    ADDCOLUMNS (
        Data,
        "@condition",
            VAR _currentid = Data[ID]
            VAR _currentrow = Data[Category]
            VAR _prevrow =
                MAXX (
                    OFFSET ( -1, Data, ORDERBY ( Data[ID], ASC ),,, MATCHBY ( Data[ID] ) ),
                    Data[Category]
                )
            RETURN
                IF ( _currentrow = _prevrow || BLANK (), 0, 1 )
    )
VAR _partition =
    ADDCOLUMNS (
        _condition,
        "@partition", SUMX ( FILTER ( _condition, Data[ID] <= EARLIER ( Data[ID] ) ), [@condition] )
    )
VAR _currentpartition =
    MINX ( FILTER ( _partition, Data[ID] = _currentid ), [@partition] )
RETURN
    MINX ( FILTER ( _partition, [@partition] = _currentpartition ), Data[ID] )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

4 REPLIES 4
IghorLima26
Frequent Visitor

Thanks @FreemanZ and @Jihwan_Kim.
The solution worked perfectly.
Very nice!!!

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

It is for creating a new column.

 

Jihwan_Kim_0-1698202860423.png

 

Result First ID CC =
MINX ( FILTER ( Data, Data[Category] = EARLIER ( Data[Category] ) ), Data[ID] )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

hi @Jihwan_Kim 

The issue is slightly different, where C=E=A and D=B. 

Hi,

Thank you for your clarification.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1698260224181.png

 

 

Result First ID CC =
VAR _currentid = Data[ID]
VAR _condition =
    ADDCOLUMNS (
        Data,
        "@condition",
            VAR _currentid = Data[ID]
            VAR _currentrow = Data[Category]
            VAR _prevrow =
                MAXX (
                    OFFSET ( -1, Data, ORDERBY ( Data[ID], ASC ),,, MATCHBY ( Data[ID] ) ),
                    Data[Category]
                )
            RETURN
                IF ( _currentrow = _prevrow || BLANK (), 0, 1 )
    )
VAR _partition =
    ADDCOLUMNS (
        _condition,
        "@partition", SUMX ( FILTER ( _condition, Data[ID] <= EARLIER ( Data[ID] ) ), [@condition] )
    )
VAR _currentpartition =
    MINX ( FILTER ( _partition, Data[ID] = _currentid ), [@partition] )
RETURN
    MINX ( FILTER ( _partition, [@partition] = _currentpartition ), Data[ID] )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

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.