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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
saddlerkayla
New Member

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
3 REPLIES 3
v-tsaipranay
Community Support
Community Support

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
New Member

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
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors