0

I'm using this code for creating a custom column!

max per group

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(
        Source,
        {{"Column1", type text}, {"Column2", Int64.Type}}
    ),
    #"Added Custom" = Table.AddColumn(
        #"Changed Type",
        "maxInt",
        each
            [
                filter = [Column1],
                max=Table.Group(
                    Source, {"Column1"},
                    {{"MaxFiltered", each List.Max([Column2])}}
                ){[Column1=filter]}[MaxFiltered]
            ][max]
    ) in
    #"Added Custom"

It works fine for getting the maxInt new column with the expected values!

But if I go on and try to reapeat the same code for adding another column to look for another maxInt but for another field, it gives me the output for this last column, and the other dissapears.

Can someone give a feedback on this matter?

Here follows my code:

    #"Added Custom" = Table.AddColumn(
        #"Changed Type",
        "maxInt",
        each
            [
                filter = [ID],
                max=Table.Group(
                    Source, {"ID"},
                    {{"MaxFiltered", each List.Max([TAX])}}
                ){[BOOKING ID=filter]}[MaxFiltered]
            ][max]
    ),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom", each if [maxInt]=[TAX] then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom1", each ([Custom] = 1)),
    #"Added Custom2" = Table.AddColumn(
    #"Changed Type",
        "maxInt2",
        each
            [
                filter = [ID],
                max2=Table.Group(
                    Source, {"ID"},
                    {{"MaxFiltered2", each List.Max([CODE])}}
                ){[BOOKING ID=filter]}[MaxFiltered2]
            ][max2]
    )
in
    #"Added Custom2"

The Added Custom Column dissapears and it only gives me the Added Custom2.

  • 2
    That is because you are adding that column to the `#"Changed Type"` step. You need to add the second custom column to last table you created, Something lke: `#"Added Custom2" = Table.AddColumn( #"Filtered Rows", ...` – Ron Rosenfeld Aug 26 '22 at 11:32
  • 2
    What Ron says. Change #"Added Custom2" = Table.AddColumn( #"Changed Type", to be #"Added Custom2" = Table.AddColumn( #"Filtered Rows", – horseyride Aug 26 '22 at 11:43
  • Thank you for thehelp! @RonRosenfeld just another doubt that came up, I wanted the second custom colum ("Added Custom2") to have the table group that considers the Added Custom1 field with values 1? To have a table filter that doens't consider the intial table, but one that has this condition, would it be possible? – chaosKnight Aug 26 '22 at 12:33
  • Thank you for the help! @horseyride just another doubt that came up, I wanted the second custom colum ("Added Custom2") to have the table group that considers the Added Custom1 field with values 1? To have a table filter that doens't consider the intial table, but one that has this condition, would it be possible? – chaosKnight Aug 26 '22 at 12:34
  • I don't understand what you are wanting to do. I suggest you post a new question, following the guidelines in the HELP pages for information as to [How to Ask a Good Question](http://stackoverflow.com/help/how-to-ask), and [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve), in order to explain better and also obtain more focused assistance. – Ron Rosenfeld Aug 26 '22 at 15:08

0 Answers0