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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Return the position of the value in a column

I want to return the position of a value in a column:

Column
A
A
A
B
B
C
C
D
E

If value is C, return 3.
If value is E, return 5.

2 ACCEPTED SOLUTIONS

Hi,

I could solve it with Query Editor and a calculated column DAX formula.  In the Query Editor, insert an Index column starting with 1.  Write this calculated column DAX formula

Column 2 = CALCULATE(DISTINCTCOUNT(Data[Column]),FILTER(Data,Data[Index]<=EARLIER(Data[Index])))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

CNENFRNL
Community Champion
Community Champion

CNENFRNL_1-1679132035032.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

8 REPLIES 8
CNENFRNL
Community Champion
Community Champion

CNENFRNL_1-1679132035032.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Ashish_Mathur
Super User
Super User

Hi,

So for the 2 rows of C, you want to see 3 two times and for the 3 rows of A, you want to see 1 three times.  Am i correct?  Also, do youw want a solution in the Query Editor?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @Ashish_Mathur, That's exactly what I want. I would prefer DAX if it's possible. 

Hi,

I could solve it with Query Editor and a calculated column DAX formula.  In the Query Editor, insert an Index column starting with 1.  Write this calculated column DAX formula

Column 2 = CALCULATE(DISTINCTCOUNT(Data[Column]),FILTER(Data,Data[Index]<=EARLIER(Data[Index])))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Ritaf1983
Super User
Super User

Hi @Anonymous
If I understand you correctly, you are interested in displaying the first instance of the value.
It can be applied as follows:
1 Add index column on PQ

Ritaf1983_0-1679109534221.png

2. create a simle min measure with dax and show it in the table / other visual you need

Ritaf1983_1-1679109772864.png

If this post helps, then please consider Accepting it as the solution and giving Kudos to help the other members find it more quickly

Simple enough, group the table before adding index.

CNENFRNL_0-1679130714166.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Anonymous
Not applicable

Hi @Ritaf1983. Thanks for your response. However, I want the second column to show 1,2,3,4,5 not  1,4,6,8,9.

In this case you can duplicate your table.

Remove duplacates, add index column as in my first solution, and yhan merge this table to yours.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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