Search code examples
excelpowerbipowerquery

Getting the next value of the same user if the type is "no type"


I'm trying to write a formula for this table that will show the subsequent value if a row containing the same user has "no type" as its type.

When Orange in column A, for instance, has a type of "no type" in column B, the result in column D will show "milk" since there is another Orange in row 4 that does not have a "no type" in column B. If "no type" is selected, the value will remain unchanged.

In addition, the following user (apple, for example) will only replicate the user's type underneath it rather than the value above.

Name Type Result
Orange No Type Milk
Orange No Type Milk
Apple Juice Juice
Orange Milk Milk
Orange No Type No Type
Apple No Type Pie
Grapes Wine Wine
Apple Pie Pie
Apple No Type No Type

I tried using this formula,

=XLOOKUP(1, ([Name]= [@Name])*([Type]<>"No Type"),[Type], [Type])

However, all of the "No type" are changed regardless whether they are above or below.

Name Type MyFormula(not correct) Expected Result
Orange No Type Milk Milk
Orange No Type Milk Milk
Apple Juice Juice Juice
Orange Milk Milk Milk
Orange No Type Milk No Type
Apple No Type Juice Pie
Grapes Wine Wine Wine
Apple Pie Juice Pie
Apple No Type Juice No Type
Banana Shake Shake Shake

Solution

  • =XLOOKUP(1;(A2:$A$11=A2)*(B2:$B$11<>"No Type");B2:$B$11;"No Type")

    enter image description here