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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
saddlerkayla
Regular Visitor

Convert Dax to M Code

I am trying to convert this DAX to M Code. I created a custom column with this DAX in the table view but I want to create this column in the Power Query editor. Please help!

 

Unique Product =
VAR CurrentProduct = 'Product Catalog'[Product Name]
VAR CurrentID = 'Product Catalog'[Index]
VAR Ranking =
    COUNTROWS(
        FILTER(
            'Product Catalog',
            'Product Catalog'[Product Name] = CurrentProduct
&& 'Product Catalog'[Index] <= CurrentID 
        )
    )
RETURN
    IF(
        Ranking > 1,
        CurrentProduct & " " & Ranking,
        CurrentProduct
1 ACCEPTED SOLUTION

Hello! This issue was resolved. I ended up being able to work it out with a simple index column. Thank you all so much!

View solution in original post

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

Share some data to work with, explain the question and show the expected result.


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

Hi @saddlerkayla ,

 

We haven’t received an update from you in some time. Could you please let us know if the issue has been resolved?
If you still require support, please let us know, we are happy to assist you.

 

Thank you.

Hello! This issue was resolved. I ended up being able to work it out with a simple index column. Thank you all so much!

Anonymous
Not applicable

Hi @saddlerkayla ,

 

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. 

 

Thank you.

Anonymous
Not applicable

Hi @saddlerkayla ,

Thanks for reaching out to the Microsoft fabric community forum. Thank you @jgeddes  for your helpful response.

 

Could you please confirm if your issue got resolved? For any further discussions or questions, please reach out to fabric community forum.

 

Thank you.

saddlerkayla
Regular Visitor

Thank you!

jgeddes
Super User
Super User

Consider example data...

jgeddes_0-1758572497845.png

You can get this result with the following code...

jgeddes_1-1758572624771.png

 

= Table.AddColumn(YourPreviousStep, "Unique Product", each let ranking = Table.RowCount(Table.SelectRows(YourPreviousStep, (r)=> [Product Name] = r[Product Name] and [Index] <= r[Index])) in if ranking > 1 then [Product Name] & " " & Number.ToText(ranking) else [Product Name], type text)

This should get you pointed in the right direction.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors