Forum Discussion

anupambit1797's avatar
anupambit1797
Iron Contributor
Sep 11, 2023

IF FORMULA

Dear Experts,

                  Need your help , So , in a column if I have "1" then print the 1st row of that column, if "0" print nothing, could you please share how to achieve this? also apart from IF , if this can also be used by Index /offset etc too.

Thanks & Regards

Anupam Shrivastava

  • NikolinoDE's avatar
    NikolinoDE
    Gold Contributor

    anupambit1797 

    To achieve the desired result in Excel, where you want to print the first row of a column if the corresponding value in that column is "1" and print nothing if the value is "0," you can use a combination of INDEX, MATCH, and IF functions.

    Let us say your data is in columns A to N, and you want to display the result in column O. In cell O1, you can enter the following formula:

    =IF(A1=1, INDEX($A$1:$N$1, MATCH(1, $A2:$N2, 0)), "")

    Here is a breakdown of how this formula works:

    • IF(A1=1, ... , ""): This part of the formula checks if cell A1 contains the value "1." If it does, it proceeds with the formula; otherwise, it returns an empty string ("") to display nothing.
    • INDEX($A$1:$N$1, ... ): If the condition is met (A1=1), it uses the INDEX function to extract the values from cells A1 to N1 (the first row of the columns).
    • MATCH(1, $A2:$N2, 0): The MATCH function is used to find the position (column number) of the first occurrence of "1" in the row containing your data (A2 to N2).

    So, this formula checks the value in cell A1. If it's "1," it looks for the corresponding column containing "1" in cells A2 to N2 and displays the value from the first row of that column. If A1 is not "1," it displays nothing ("").

    You can then drag this formula down in column O to apply it to the entire dataset.

    This approach uses INDEX, MATCH, and IF functions to conditionally retrieve and display the data based on the presence of "1" or "0" in the first row of each column. The text, steps and functions were created with the help of AI.

     

    My answers are voluntary and without guarantee!

     

    Hope this will help you.

    Was the answer useful? Mark them as helpful and like it!

    This will help all forum participants.

  • Patrick2788's avatar
    Patrick2788
    Silver Contributor

    anupambit1797 

    This will do it:

     

    =LET(
        cols, COLUMNS(header),
        matrix, (rgb = 1) * SEQUENCE(, cols),
        print_header, LAMBDA(element,
            IF(element > 0, INDEX(header, , element), "")
        ),
        MAP(matrix, print_header)
    )

     

  • anupambit1797 

    =MAKEARRAY(ROWS(A2:G9),COLUMNS(A2:G9),LAMBDA(r,c,IF(INDEX(A2:G9,r,c)=1,INDEX(A1:G1,,c),"")))

    An alternative with Office 365 or Excel for the web could be this formula.

     

Share

Resources