Forum Discussion

powerbifuddaa's avatar
powerbifuddaa
Icon for Helper II rankHelper II
2 years ago

rankx dax

Hi all,

I would like to see this (rank_desired):

I can only use DAX.

I hope somebody can help me. Thank you!

Regards, Elmer

9 Replies

  • AilleryO's avatar
    AilleryO
    Icon for Memorable Member rankMemorable Member

    Hi,

    It would help us if you could tell us what is the logic of your ranking,

    and could you please post some datas (without any sensitive data) we can copy and paste.

    It should be a RANKX without forgetting to remove filters unwanted with ALL function (at least on Dpt, and dates...).

    Hope it helps otherwise please give us more details

    • powerbifuddaa's avatar
      powerbifuddaa
      Icon for Helper II rankHelper II

      Hi, shown are all the mutations of employer A. The logic of my ranking is: employer A is in what department on what startdate.

       

      CustomerStartDateEndDatedepartmentrank_desired
      A1-1-201431-8-20211000261
      A1-9-202131-12-20211000261
      A1-1-202231-1-20221000261
      A1-2-202228-2-20221000261
      A1-3-202230-6-20221005452
      A1-7-202231-8-20221005452
      A1-9-20221-3-20231005452
      A2-3-20235-3-20231005653
      A6-3-202331-3-20231005454
      A1-4-20232-10-20231005454
      A3-10-202331-12-20991005454

       

      Desired with earliest startdate and latest enddate:

      If you need more information, please let me know.

      Thanx, Elmer

       

       

    • powerbifuddaa's avatar
      powerbifuddaa
      Icon for Helper II rankHelper II

      ChiragGarg2512 

      Thank you for your answer. It did not work (yet). I get this message:

      After using "value" it showed 2 for every line

  • AilleryO's avatar
    AilleryO
    Icon for Memorable Member rankMemorable Member

    Hi,

    If I understood your needs :

    Latest Date in Dpt =
    VAR CurrDpt = SELECTEDVALUE( TableEmployee[department] )
    RETURN
    CALCULATE( LASTDATE( TableEmployee[EndDate] ) , ALL(TableEmployee) , TableEmployee[department]=CurrDpt )
    and
    Earliest Date in Dpt =
    VAR CurrDpt = SELECTEDVALUE( TableEmployee[department] )
    RETURN
    CALCULATE( FIRSTDATE( TableEmployee[StartDate] ) , ALL(TableEmployee) , TableEmployee[department]=CurrDpt )
    you should get this :

    Let us know if it works

    • powerbifuddaa's avatar
      powerbifuddaa
      Icon for Helper II rankHelper II

      Thank you AilleryO 

      I already got this result with earliest and latest.

       

      What I am really trying to achieve is:

       

      Most people go from department 1,2,3,4

      But there are also people who go 1,2,3,2 (like in this case)

       

      Hope you have another idea. Thank you. Regards, Elmer

  • Nothing to do with RANKX(). Simplest table grouping in PQ does the trick.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ddBBCsAgDATAv3huINmo1WPfUfz/N2ppU1PE25IdVvA8wxG2ICQEltijCpWeIfeZmZFD20xVa7oSLNk9BrzM8qRgDcrIk9Jviyk7lWJyancvlqWqX/PM6owwmvRHeaA8Gl1PCUVrQMILpa6yX63VuXYB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, StartDate = _t, EndDate = _t, Department = _t]),
    
        Grouped = Table.AddIndexColumn(Table.Group(Source, "Department", {"Grp", each _}, GroupKind.Local),"SN",1,1),
        #"Expanded Grp" = Table.ExpandTableColumn(Grouped, "Grp", {"Customer", "StartDate", "EndDate"}, {"Customer", "StartDate", "EndDate"})
    in
        #"Expanded Grp"

    • AilleryO's avatar
      AilleryO
      Icon for Memorable Member rankMemorable Member

      Thanks you for your proposal but powerbifuddaa specify that he can use only DAX

      so a Power Query solution might not be valid for him.

    • powerbifuddaa's avatar
      powerbifuddaa
      Icon for Helper II rankHelper II

      ThxAlot: If you could tell me how to do this in dax, I would be very gratefull! ThxAlot. Regards, Elmer