Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Table.RowCount all rows in current table for use in a custom column equation

I want a custom column where if a row in another column is blank, then return blank, but if it has ANY value, then return (1/ Total # of Rows in current Table)   I am trying this.    = Table.AddC...
  • tackytechtom's avatar
    3 years ago

    Hi Anonymous,

     

    Cyclic references are a bit tricky sometimes. One way to solve your issue is to save the number of rows in a step before and then reference that variable:

     

    Before:

     

    After:

     

    And here the code in M:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1YlWKsisqkoEs9CIksTk7MqS1OQMpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column", type text}}),
        #"Replaced Value" = Table.ReplaceValue(#"Changed Type","",null,Replacer.ReplaceValue,{"Column"}),
        #"countrows" = Table.RowCount(#"Replaced Value"),
        #"Added Custom" = Table.AddColumn(#"Replaced Value", "Custom", each if [Column] <> null then 1 / #"countrows"
     else null)
    in
        #"Added Custom"

     

    Let me know if this helps 🙂

     

    /Tom
    https://www.tackytech.blog/
    https://www.instagram.com/tackytechtom/