Forum Discussion

Doro's avatar
Doro
Frequent Visitor
4 years ago
Solved

Replace duplicated value counting two columns...

Up         Down      Idea
104 K         1
104 K         1
104 K         1           4
105 K         1
105 K         1
105 K         1           4
106 K         1
106 K         1
106 K         1           4
104 K         2
104 K         2
104 K         2           4
105 K         2
105 K         2
105 K         2          4
106 K         2
106 K         2
106 K         2          4
104 K         3
104 K         3
104 K         3          4
105 K         3
105 K         3
105 K         3          4
106 K         3
106 K         3
106 K         3          4

 

Hello, dear forum minds need a help on one task, i would like my data looks like column "Idea", and the point is to insert value "4" after cycle of column "Up" is breaking on unique number, somtimes its getting repited and then need to be taken to acount column "Down". Thank you great mind in advance!

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Doro 

     

    I am not sure if you want to keep distinct values for Up + Down? It is very easy to identify the first combination, just add Index, and if you don't need the rest, just keep the first one as not sure how many for each combination...let me know if you need something else

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQw8T60QElH6dACQ6VYHQICQBoiZIquBo8AXJMZuho8AnBNJt5AASPcHCQnIclh4SA5A0kOCwfVamPcHFSrjXFzUK02xs0BKYwFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Up " = _t, #" Down " = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Up ", type text}, {" Down ", Int64.Type}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"Up ", " Down "}, {{"allrows", each Table.AddIndexColumn(_,"index",0,1)  }}),
        #"Removed Other Columns" = Table.SelectColumns(#"Grouped Rows",{"allrows"}),
        #"Expanded allrows" = Table.ExpandTableColumn(#"Removed Other Columns", "allrows", {"Up ", " Down ", "index"}),
        Custom = Table.TransformColumns(#"Expanded allrows", {{"index", each if _=0 then _ else null}})
    in
        Custom

     

7 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Doro 

     

    I am not sure if you want to keep distinct values for Up + Down? It is very easy to identify the first combination, just add Index, and if you don't need the rest, just keep the first one as not sure how many for each combination...let me know if you need something else

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQw8T60QElH6dACQ6VYHQICQBoiZIquBo8AXJMZuho8AnBNJt5AASPcHCQnIclh4SA5A0kOCwfVamPcHFSrjXFzUK02xs0BKYwFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Up " = _t, #" Down " = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Up ", type text}, {" Down ", Int64.Type}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"Up ", " Down "}, {{"allrows", each Table.AddIndexColumn(_,"index",0,1)  }}),
        #"Removed Other Columns" = Table.SelectColumns(#"Grouped Rows",{"allrows"}),
        #"Expanded allrows" = Table.ExpandTableColumn(#"Removed Other Columns", "allrows", {"Up ", " Down ", "index"}),
        Custom = Table.TransformColumns(#"Expanded allrows", {{"index", each if _=0 then _ else null}})
    in
        Custom

     

    • Doro's avatar
      Doro
      Frequent Visitor

      Hi Anonymous ,

      Thank you for the quick reply, but now I think I posted this request in the wrong branch because I don't know how to apply or even test your answer (dummy me) each time I paste this bit of code in the advanced editor, I get errors...
      I did some research and added a column "sh" with formula, but it worked till column "down" changed value, so that's why I was considering a distinct value based on two columns. Maybe there  is a way to work on this direction...

       

       

       

      sh = 
      VAR a = CALCULATE(MAX('testFile'[Up]),FILTER('testFile','testFile'[Index]<EARLIER('testFile'[Index])))
      RETURN IF('testFile'[Up]<>a,8,0)

       

       

       

      shUpDownIndexIdea
      8104 K114
      0104 K12 
      0104 K13 
      8105 K144
      0105 K15 
      0105 K16 
      8106 K174
      0106 K18 
      0106 K19 
      8104 K2104
      8104 K211 
      8104 K212 
      8105 K2134
      8105 K214 
      8105 K215 
      0106 K2164
      0106 K217 
      0106 K218 
      8104 K3194
      8104 K320 
      8104 K321 
      8105 K3224
      8105 K323 
      8105 K324 
      0106 K3254
      0106 K326 
      0106 K327