1

In R I can write

neighbours<-c("Merton",
              "Southwark","Sutton","Wandsworth",
              "Bromley")

And then filter a dataframe like

df %>% filter(neighbours %in% boroughs_of_london)

And it can get even more complex if you follow something like this:

Multiple strings with str_detect R

The question I have, as tidyverse dplyr is very much like SQL which is like DAX (right?), is

Can I and how do I filter by a vector/variable in DAX?

EDIT: In DAX you'd probably write

FILTER (
    LONDON,
    LONDON[boroughs_of_london]
        IN { "Merton", "Southwark", "Sutton", "Wandsworth", "Bromley" }
)

Is this correct?

FILTER (
    LONDON,
    LONDON[boroughs_of_london] IN { neighbours }
)
Alexis Olson
  • 38,724
  • 7
  • 42
  • 64
damo
  • 463
  • 4
  • 14
  • Can you specify your input and desired output? I think it will be easier to understand than formulating the question in relation to R. – Alexis Olson Nov 30 '20 at 21:18

1 Answers1

0

In DAX, you can certainly have variables that are scalars, vectors, or tables.

The following is valid:

LondonNeighbours =
VAR neighbours = { "Merton", "Southwark", "Sutton", "Wandsworth", "Bromley" }
RETURN
    FILTER ( LONDON, LONDON[boroughs_of_london] IN neighbours )

The result is a calculated table that is the rows of the LONDON table filtered down to only those specified boroughs.

The syntax inside FILTER will remain the same whether the neighbors variable is hardcoded (in the example above), dynamically determined based on slicers and/or filter context, or a fixed reference to other table(s).

Alexis Olson
  • 38,724
  • 7
  • 42
  • 64
  • Brilliant. Thank you. – damo Nov 30 '20 at 22:33
  • In the answer you've given is it possible to use LIKE. FILTER(LONDON, LONDON[boroughs_of_london] IN LIKE(neighbours )) ? or is it possible at VAR neighbours = {"Mer*","South*"} (any link to go off and read further also appreciated so I stop pecking at the same questions... :) – damo Dec 01 '20 at 09:29
  • Those constructions don't work. There may be ways to do something similar but it would be best to frame the question in terms of what you are ultimately trying to do with your data than trying to find direct syntax equivalences. – Alexis Olson Dec 01 '20 at 14:10