Forum Discussion

Mehmed91's avatar
Mehmed91
Copper Contributor
Jun 18, 2023

Index and match #N/A

Greetings everyone! I am trying to create an index/match where it checks the teaching subject in a certain city and returns the most selling teacher in that area, but it keeps returning #N/A ...
  • SergeiBaklan's avatar
    Jun 18, 2023

    Mehmed91 

    In addition, I'd adjust the logic a bit. You are searching max sales count for given combination of subject and city. For that max sales count you return Teacher name.

    However, same Sales count as found max one could be for another record. If so you return first of the, subject and city criteria are not applied again after the mas was found.

    On such sample

    your formula

    =INDEX(Shamal_D[Teacher_name], MATCH(MAX(IF((Shamal_D[Subject]=[@Subject])*(Shamal_D[city]=[@City]), Shamal_D[Sales Count], -1)), Shamal_D[Sales Count], 0))

    returns result for top left table.

    Bit modified formula

    =LET(
        criteria, (Shamal_D[Subject] = [@Subject]) * (Shamal_D[city] = [@City]),
        maxSales, AGGREGATE(14, 6, 1 / criteria * Shamal_D[Sales Count], 1),
        position, XMATCH(1, criteria * (Shamal_D[Sales Count] = maxSales), 0),
        IFERROR( INDEX(Shamal_D[Teacher_name], position), "wrong data" )
    )

    is in bottom left table.

Resources