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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
KamphuisB
Frequent Visitor

Count text values in column +1 DAX formula

Dear Power BI Users,

 

I am a bit new to the DAX formulas. I have searched a lot on the forum but i haven't found my answer for the following question. 

 

I would like to create a calculated column to count the text duplicates in a specific order, that it looks to the previous rows of data of the column. See data example below:

ColumnA  ColumnB

A1
B1
C1
D1
A2
E1
F1
B2
A3
D2
G1
H1
A4

 

How can i create calculated column B with DAX? 

 

Thanks for your help!

 

Kind regards,

 

Bas Kamphuis

1 ACCEPTED SOLUTION
v-huizhn-msft
Microsoft Employee
Microsoft Employee

Hi @KamphuisB,

For your requirement, you’d better add a index column, and calculate the result based on the index column. I reproduce your scenario and get desired result as follows.

Click the table, right click->Edit Query. In the Power Query Editor, under Add column, click add index column highlighted in yellow. You will get the index from first rows shown in following screenshot.


1.png


Then create another calculated column using the formula below.

ColumnB = RANKX(FILTER(Test1,Test1[ColumnA]=EARLIER(Test1[ColumnA])),Test1[Index],,ASC)




 2.png

 

If you have any other issue, please feel free to ask.

Best Regards,
Angelia

View solution in original post

5 REPLIES 5
v-huizhn-msft
Microsoft Employee
Microsoft Employee

Hi @KamphuisB,

For your requirement, you’d better add a index column, and calculate the result based on the index column. I reproduce your scenario and get desired result as follows.

Click the table, right click->Edit Query. In the Power Query Editor, under Add column, click add index column highlighted in yellow. You will get the index from first rows shown in following screenshot.


1.png


Then create another calculated column using the formula below.

ColumnB = RANKX(FILTER(Test1,Test1[ColumnA]=EARLIER(Test1[ColumnA])),Test1[Index],,ASC)




 2.png

 

If you have any other issue, please feel free to ask.

Best Regards,
Angelia

Hi Angelia,


Thanks for answering my question. it worked with a calculated column!

 

I have one question: Is it also possible to make the RANKX column in the query editor? Then i get an expression error RANKX not recognised.

 

With kind regards,

 

Bas Kamphuis

Hi Angelia,

 

I have the results that i wanted. The reason i asked the question above was that i needed a table with only the results of the RANKX =1 column. Since you can only really filter out the data inside the query editor, i made an New table with FILTER('Table','Table'[RANKX COLUMN] = 1)

 

 

With kind regards,

 

Bas Kamphuis

HIi @KamphuisB,

I am very glad you have resolved your issue. If you have any other issue, please feel free to ask in this forum.

Best Regards,
Aneglia

Baskar
Resident Rockstar
Resident Rockstar

very simple dude.

 

drag your column A in  and Drag Column B too.

 

In column B change the default summarization to count . Thats it .

 

 

or do u want any measure , we can ctreate it .

 

Measure = count(column B)

 

Thats it, 

 

let me know if any help

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors