# take_anyif



`take_anyif` returns a value from an arbitrary row that matches a condition in each group.

## Usage [#usage]

### Syntax [#syntax]

```kusto
summarize take_anyif(expr, predicate) [by GroupingColumn]
```

### Parameters [#parameters]

* **`expr`**: The expression to return a value for.
* **`predicate`**: A Boolean expression that selects the rows to consider.
* **`GroupingColumn`** (optional): A column to group the results by. If you omit it, all records form one group.

### Returns [#returns]

Returns a value from a matching row in each group, skipping nulls and empty strings. If no rows match, or all matching values are null or empty strings, it returns `null`.

`anyif` is a deprecated alias of `take_anyif`.

## Use case examples [#use-case-examples]

### One failing URI for each service [#one-failing-uri-for-each-service]

This example returns one URI with status `500` for each service. `frontend` has no matching request, so its result is `null`.

**Query**

```kusto
datatable(service: string, status: string, uri: string)[
  'checkout', '500', '/cart',
  'checkout', '200', '/pay',
  'frontend', '200', '/home',
]
| summarize failed_uri = take_anyif(uri, status == '500'), requests = count() by service
```

**Output**

| service  | failed\_uri | requests |
| -------- | ----------- | -------- |
| checkout | /cart       | 2        |
| frontend |             | 1        |

## List of related aggregations [#list-of-related-aggregations]

* [**take\_any**](/apl/aggregation-function/take-any): Returns the values of one arbitrary row for each group, without a predicate.
* [**countif**](/apl/aggregation-function/countif): Counts the records for which a predicate is true.
* [**make\_set\_if**](/apl/aggregation-function/make-set-if): Returns all distinct values of an expression for which a predicate is true.

## Other query languages [#other-query-languages]

<LanguageComparisons>
  <Accordion title="ANSI SQL users">
    In ANSI SQL, you combine `ANY_VALUE` with a `CASE` expression to return an arbitrary value from matching rows.

    <CodeGroup>
      ```sql SQL example
      SELECT method, ANY_VALUE(CASE WHEN status = '500' THEN uri END)
      FROM sample_http_logs
      GROUP BY method
      ```

      ```kusto APL equivalent
      ['sample-http-logs']
      | summarize take_anyif(uri, status == '500') by method
      ```
    </CodeGroup>
  </Accordion>
</LanguageComparisons>
