Forum Discussion

KristofferAJ's avatar
KristofferAJ
Helper III
4 years ago
Solved

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
  • Nathaniel_C's avatar
    Nathaniel_C
    4 years ago

    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.

     

    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

6 Replies

      • Nathaniel_C's avatar
        Nathaniel_C
        Community Champion

        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.

         

        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

  • Anonymous's avatar
    Anonymous
    Not applicable

    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.

    2.Add a custom column to count rows.

    3.Expand the [Custom] column.

    4.Add a custom column to get the results.

     

    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.