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
KristofferAJ
Helper III
Helper III

Convert DAX column into power query (add column)

Hi,
I have this column which I use for scoring/ranking across varius type of FRUIT sold. It works really well, I'm moving into a bigger data set and I want to see if I can move this directly into power query...
 
How do I write the code  in the 'add column in power query? - is it at all possible?
 
COLUMN NAME =
VAR NCT = CTL[FRUIT Code]
VAR filteredTable = FILTER ( CTL, NOT ( ISBLANK ( CTL[(PQ) PSM] ) ) && CTL[FRUIT Code] = NCT)

RETURN
IF(ISBLANK(CTL[(PQ) PSM]),BLANK(),
DIVIDE (
RANKX (
filteredTable,
CTL[(PQ) PSM],
,
ASC
) - 1,
COUNTROWS ( filteredTable ) - 1
))*100
1 ACCEPTED SOLUTION

Hi @KristofferAJ ,
The most interesting think in your measure is the rank.  I have never seen that done in Power Query.  Here is what I found, and it is very cool.  

https://data-witches.com/2020/10/21/adding-a-row-rank-based-on-a-different-column-with-power-query/

The picture below is daxformatter.com and I would highly recommend this to you.

Nathaniel_C_0-1653959690684.png

 

Nathaniel_C_1-1653961162517.png

I will send you my pbix.  The second issue is counting the number of rows by fruit, which is simply using groupby in Power Query.


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





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

Proud to be a Super User!




View solution in original post

6 REPLIES 6
ronrsnfld
Super User
Super User

Take a look at Convert DAX column into Power Query (add column)

Seems to be the same question.

v-stephen-msft
Community Support
Community Support

Hi @KristofferAJ ,

 

Ranking in the power query is easy, here's the video for reference.

1.According to the tutorial in the video above, get the [Rank] column.

vstephenmsft_0-1654155292941.png

2.Add a custom column to count rows.

vstephenmsft_1-1654155439484.png

vstephenmsft_2-1654155446494.png

3.Expand the [Custom] column.

vstephenmsft_3-1654155499285.png

vstephenmsft_4-1654155505764.png

4.Add a custom column to get the results.

vstephenmsft_7-1654155668546.png

vstephenmsft_8-1654155675228.png

vstephenmsft_9-1654155702874.png

 

You can check more details from my attachment.

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Nathaniel_C
Community Champion
Community Champion

Hi @KristofferAJ 


If you would share your pbix, or dummy up some values in Excel both for current and expected data. Please copy and paste them into your post, rather than doing a picture, we may be able to help you. 

Please read this post to get your question answered more quickly:

https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

Nathaniel 





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

Proud to be a Super User!




Hi @Nathaniel_C 
Thanks for your interest. I have made a dummy pBIX with the formula as I have it now, my wish is to have the "COLUMN NAME" directly in powerquery preferebly by 'add column'

 

I have placed the file here, as I can't see an ooption to upload here..

 

https://www.dropbox.com/s/trrdggjz4c1x3ff/Test_scoringrank_in_powerquery.pbix?dl=0

 

Thanks

Kristoffer


Hi @KristofferAJ ,
The most interesting think in your measure is the rank.  I have never seen that done in Power Query.  Here is what I found, and it is very cool.  

https://data-witches.com/2020/10/21/adding-a-row-rank-based-on-a-different-column-with-power-query/

The picture below is daxformatter.com and I would highly recommend this to you.

Nathaniel_C_0-1653959690684.png

 

Nathaniel_C_1-1653961162517.png

I will send you my pbix.  The second issue is counting the number of rows by fruit, which is simply using groupby in Power Query.


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





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

Proud to be a Super User!




PBIX https://1drv.ms/u/s!AgCd7AyfqZtE4ShMLbd1zhJPNDvX?e=kjNvFh 





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

Proud to be a Super User!




Helpful resources

Announcements
ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Kudoed Authors