Forum Discussion

seenai's avatar
seenai
Helper II
4 years ago
Solved

Add Custom Column 'Batch'

Hi,

 

I need to add 'custom column' like Index, in the below scenario :

 

The Index number changes only when change in ModelNo.

Request your inputs.

 

  • Hi seenai ,

     

    1. Add the Index column.

     

     

    2. Add the following custom columns in Power Query Editor.

     

    = if [Index]=1 then null else #"Added Index"{[Index]-2}[ModelNo]

    = if [ModelNo]=[PrevRow] and [Index]-#"Added Custom"{[Index]-2}[Index]=1 then 1 else 0

     

    3. Create calculated columns:

     

    Index2 = 
    VAR MaxIndex =
        MAXX (
            FILTER (
                'Table',
                'Table'[Index] < EARLIER ( 'Table'[Index] )
                    && 'Table'[Custom] = 0
            ),
            'Table'[Index]
        )
    RETURN
        IF ( 'Table'[Custom] = 0, 'Table'[Index], MaxIndex )
    Order = RANKX ( 'Table', 'Table'[Index2], , ASC, Dense )

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

    Best Regards,
    Winniz

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

     

2 Replies

  • seenai add a rank column, follow these posts.

     

    Follow us on LinkedIn

     

    Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

  • v-kkf-msft's avatar
    v-kkf-msft
    Community Support

    Hi seenai ,

     

    1. Add the Index column.

     

     

    2. Add the following custom columns in Power Query Editor.

     

    = if [Index]=1 then null else #"Added Index"{[Index]-2}[ModelNo]

    = if [ModelNo]=[PrevRow] and [Index]-#"Added Custom"{[Index]-2}[Index]=1 then 1 else 0

     

    3. Create calculated columns:

     

    Index2 = 
    VAR MaxIndex =
        MAXX (
            FILTER (
                'Table',
                'Table'[Index] < EARLIER ( 'Table'[Index] )
                    && 'Table'[Custom] = 0
            ),
            'Table'[Index]
        )
    RETURN
        IF ( 'Table'[Custom] = 0, 'Table'[Index], MaxIndex )
    Order = RANKX ( 'Table', 'Table'[Index2], , ASC, Dense )

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

    Best Regards,
    Winniz

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