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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
BYENER
Helper V
Helper V

Add an index column based on a if formula

Hi All,

 

Can someone help me with the following? I have to columns, column A with text value and column B the value of previous row of column A. Now I want to add another column (index) and will start with 1 and after if column A and column B are the same the value has to stay 1 else it have to be + 1.

 

For example

 

Column AColumn BIndex
ABlank1
AA1
AA1
BA2
BB2
AB3
AA3
AA3
CA4
CC4
CC4
 C 

 

Thanks in advance.

10 REPLIES 10
v-eqin-msft
Community Support
Community Support

Hi @BYENER ,

Did I answer your question? Please mark my reply as solution, thank you~

 

Best regards,

Eyelyn Qin

 

Hi @v-eqin-msft ,

 

My apologies, I didn't saw your message. Thank you for your solution. This is exactly what I want, but you asked me to put the formula in the query editor. Do you mean DAX or advanced editor in Power Query? I want this in Powery Query because after this I want to group by Index.

 

Kind regards,

B. Yener

 

 

Hi @BYENER ,

Sorry for the confusion. I mean to add a Index column in Query Editor.

8.25.fo.png

The DAX formula is used out of Query Editor.

 

Best regards,

Eyelyn Qin

.

@v-eqin-msftformula is not working. Please see attached pbix file.

 

text pbix 

@v-eqin-msft  did you opened the test pbix?

Can nobody help me?

v-eqin-msft
Community Support
Community Support

Hi @BYENER ,

According to my understanding, you want to accumulate based on index,  right?

 

You could use the following formula after add a Index column in Query Editor:

flag =
VAR _last =
    LOOKUPVALUE (
        'IndexTable'[Column A],
        'IndexTable'[Original Index], SELECTEDVALUE ( 'IndexTable'[Original Index] ) - 1
    )
RETURN
    IF (
        SELECTEDVALUE ( 'IndexTable'[Original Index] ) = 1,
        1,
        IF ( SELECTEDVALUE ( IndexTable[Column A] ) = _last, 0, 1 )
)
Accumulate =
SUMX (
    FILTER (
        ALL ( IndexTable ),
        IndexTable[Original Index] <= MAX ( IndexTable[Original Index] )
    ),
    [flag]
)

My visualization looks like this:

8.26.3.1.png

Is the result what you want? If you have any questions, please upload some data samples and expected output.

Please do mask sensitive data before uploading.

 

Best Regards,

Eyelyn Qin

amitchandak
Super User
Super User

@BYENER , refer to if the file attached after signature can help.

You can merge two columns into one

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Yes, that's exactly what I did Index and Index 1 , but you added the new column in DAX. I want to add in Power Query, because I want to use the group by function.

 

 

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! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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