Forum Discussion

M_SBS_6's avatar
M_SBS_6
Helper V
8 months ago
Solved

Power Query Tables

Hi, I have connected to an excel file and within the 1 sheet, there are 3 tables. Each month a new row is added to each table but the column headers always stay the same.  I only need to bring i...
  • Zanqueta's avatar
    8 months ago

    Hi M_SBS_6,

     

    Unfurtunelly we don´t have a sample data to teste, but please try it:

     

    1. Load the entire sheet (not just a single table).
    2. In the Power Query editor:
      • Identify the column where the value "test errors" appears.
      • Apply logic to keep all rows from that point onwards and exclude the rest.
      • This can be done using an index and conditional filtering

     

    Input Steps

    # Add an index column
    = Table.AddIndexColumn(PreviousStep, "Index", 0, 1, Int64.Type)
    
    # Find the position of the row where Column1 = "test errors":
    Position = Table.PositionOf(PreviousStep, [Column1 = "test errors"])
    
    # Skip all rows above that position:
    = Table.Skip(PreviousStep, Position)

     

    If this response was helpful in any way, I’d gladly accept a 👍much like the joy of seeing a DAX measure work first time without needing another FILTER.

    Please mark it as the correct solution. It helps other community members find their way faster (and saves them from another endless loop 🌀.

     

  • danextian's avatar
    8 months ago

    Hi M_SBS_6 

     

    Assuming each month section has its own header, identify the row position of that header after the top table and use that index to extract the corresponding rows. If the monthly sections share the same header as the top table, instead locate the first blank or null row—whichever applies—provided that column values do not contain nulls.

    Sample code:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("7VjLblzJDf0VQevBFavIYrGWySDxaoAATlYDLxp2JxFitQJJE2T+PoeP2+qJ2l4kgFcGBKj61ovPw8P6+efbH/9+OJ2On2/+dHh6OR2fnm9/uP3xcDp8OmDQVxu6NcVwNNOxifjXvrht5MNGQ9fWOoasnWxTH3ZSm7lNldq2Yt6oty3391n7lYR9Uvpac1Pz2Ua9LmqzqW5+DJMMy82DZWyxaQzpuvkeWa2pbE1uP/xwVaM/Ph1OH4++XXiNrcdFY9iqIa3V8iKWtg0/vdlopVpvXVv8l7k2DdGWQDH1LZBcUyARnLkfvkg2Tokhpx/dJswmMWtz1DU4mXWbMRRrnFJMSEQb65f0eX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LEu4B8bzHfTydZTb4iwZneHo1itu010NU9ikwhQHO53cGfPtNwfH9w+Hz55vf//J8fzo+/+aNF9DU8qENZDRqKy9/eI1E1JXvUgw3BxYQcT25gdYVDTCyc1NnI0Fuct9JArqg7FVlcFBC9HYrCrpTbs53KJTngACAsYY0kAFEeV0X/hUhEcQpqWm+bREiLI4EQwgBkWmgapV/c8RDLtqxlsmu3njHFPhucdcUDpzLYrFgcTwDg5am8qClngshuFO4WE0avStqyMJ4G9clf4VICIimME5DHxLnD+mWujfLd2ccGp2HN68xwH2FRRyMZQBH8u2ZKEWaTvJ9rff4qRI4rqR1vS8O6wCuYj9IYb64wGFgt3Zd6lcuCk+l/1e9SioaY6qqVycR9YAflCvJRHHSGDYdWF3PONkaY9NcPRtnwEw9jucdEDeR3yWL1x2QWM0eHUqmuaEPQuy62F9ByekMP1+Jvd+P+jKU5/6cnDHY0RMEgnev/j6gevtAJwPE9i+CBIioBrhXty+5S0EZZ3UZGumDat32F75paSOsSeoJio4ae/vhw38A", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Segment = _t, Country = _t, #"30/09/2013" = _t, #"31/10/2013" = _t, #"30/11/2013" = _t, #"31/12/2013" = _t, #"31/01/2014" = _t, #"28/02/2014" = _t, #"31/03/2014" = _t, #"30/04/2014" = _t, #"31/05/2014" = _t, #"30/06/2014" = _t, #"31/07/2014" = _t, #"31/08/2014" = _t, #"30/09/2014" = _t, #"31/10/2014" = _t, #"30/11/2014" = _t, #"31/12/2014" = _t, #"Grand Total" = _t]),
        Custom1 = let 
    tbl = Source, //name of the previous applied step
    NextHeader = List.PositionOf(tbl[Segment], "Segment") //tbl[Segment] --access the first column as a list then find the position of "segment" other than the header
    in
    Table.FirstN(tbl, NextHeader)
    in
        Custom1