Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Dynamic row numbers based on Rank Column

Hell All,

 

I have written a calculated column to get the ranks for each sbu's employee count.

Formula:-

 

 

Ranks = 
    RANKX(
        FILTER('Table','Table'[Date]=EARLIER('Table'[Date])),
        'Table'[Count],,,Dense)

Ouput:-

Now i would like to get the count of rows which changes dynamically based on rank column.
i.e

SBUCountRanksRowNum
A3311
B922
C533
D344
E345
F256
G257
H168
I169
J1610

 

 

Can anyone please suggest me for the same.

 

Thanks

Mohan V

 

  • Anonymous's avatar
    Anonymous
    8 years ago

    Well i got a solution on my own..but its not by using DAX..
    Its magic power query.

     

    Solution:-

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdFNCoAgEIbhu8xaMJ0iW1ba3xXE+18jUSonvp08DDO8GCPNpKjXVtvOuPycKKlIi0RTcJXIBb1EWzCgyQ3t3BEeEoeCJzp0/Q7VSzWJH3VNEqMklks9wiCxTWKUxCjpxbFJYpT0Yf6QdAM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [SBU = _t, Date = _t, Count = _t]),
        #"Changed Type1" = Table.TransformColumnTypes(Source,{{"Count", Int64.Type}}),
        #"Sorted Rows" = Table.Sort(#"Changed Type1",{{"Date", Order.Ascending}, {"Count", Order.Descending}}),
        #"Changed Type" = Table.TransformColumnTypes(#"Sorted Rows",{{"Count", Int64.Type}, {"Date", type date}}),
    
        Partition = Table.Group(#"Changed Type", {"Date"}, {{"Count", each Table.AddIndexColumn(_, "Index2",1,1), type table}}),
        #"Expanded Count" = Table.ExpandTableColumn(Partition, "Count", {"SBU", "Count", "Index2"}, {"SBU", "Count.1", "Index2"}),
        #"Changed Type2" = Table.TransformColumnTypes(#"Expanded Count",{{"SBU", type text}, {"Count.1", Int64.Type}, {"Index2", Int64.Type}})
    in
        #"Changed Type2"

    Thanks for the help Anonymous

     

4 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Anonymous Thanks for the confirmation.

      Well i think i need to go by a workaround solution for what i am looking for.

      I ll give you detailed infor regarding the report that i am creating.
      I hope and i wish you will come up with some suggestions or workaround solutions.

       

      Actually, i am creating report, which is having all the cards visual for each sbu.

      if i have ten sbu's then ten cards visual for each sbu which shows the emp count.

      Now i would like to show these cards by their ranks based on emp count, which are changing dynamically for each day for each sbu.

      i.e the top rank sbu card will be first and then the second by putting this ranks calculated column in visual level filter.

      But here as you know some of the sbu's having same no emp count, then i cant go with ranks.

       

      So thats the reason i would like to have a column or measure which will be giving the index/rownum based on the ranks.

       

      Expected output:-

      SBUCountRanksIndex
      A344
      B256
      C168
      D3311
      E345
      F257
      G922
      H169
      I533
      J1610

       

       

      So here if you see, 4,5,6 ranks are getting repeated.

      for those i would like to have a column or measure which will give me 

       

      Please help.

       

      Mohan V

      • Anonymous's avatar
        Anonymous
        Not applicable

        Well i got a solution on my own..but its not by using DAX..
        Its magic power query.

         

        Solution:-

         

        let
            Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdFNCoAgEIbhu8xaMJ0iW1ba3xXE+18jUSonvp08DDO8GCPNpKjXVtvOuPycKKlIi0RTcJXIBb1EWzCgyQ3t3BEeEoeCJzp0/Q7VSzWJH3VNEqMklks9wiCxTWKUxCjpxbFJYpT0Yf6QdAM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [SBU = _t, Date = _t, Count = _t]),
            #"Changed Type1" = Table.TransformColumnTypes(Source,{{"Count", Int64.Type}}),
            #"Sorted Rows" = Table.Sort(#"Changed Type1",{{"Date", Order.Ascending}, {"Count", Order.Descending}}),
            #"Changed Type" = Table.TransformColumnTypes(#"Sorted Rows",{{"Count", Int64.Type}, {"Date", type date}}),
        
            Partition = Table.Group(#"Changed Type", {"Date"}, {{"Count", each Table.AddIndexColumn(_, "Index2",1,1), type table}}),
            #"Expanded Count" = Table.ExpandTableColumn(Partition, "Count", {"SBU", "Count", "Index2"}, {"SBU", "Count.1", "Index2"}),
            #"Changed Type2" = Table.TransformColumnTypes(#"Expanded Count",{{"SBU", type text}, {"Count.1", Int64.Type}, {"Index2", Int64.Type}})
        in
            #"Changed Type2"

        Thanks for the help Anonymous