Forum Discussion
How to sort area codes using DAX
- Anonymous5 years ago
goncalogeraldes helped me figure out a solution using nested if statements 🙂
For anyone else struggling, here's an example of what I used:
= Table.AddColumn(#"Renamed Columns3", "Region", each if Text.Start([AreaCode],2) = "SW" then "South-West" else /* for conditions where you need the first 2 letters */ if Text.Start([AreaCode],2) = "SE" then "South-East" else if Text.Start([AreaCode],2) = "BR" then "Bromley" else if Text.Start([AreaCode],2) = "WC" then "West-Central" else if Text.Start([AreaCode],2) = "EC" then "East-Central" else if Text.Start([AreaCode],2) = "NW" then "North-West" else if Text.Start([AreaCode],1) = "E" then "East" else /* for conditions where you only need the first letter */ if Text.Start([AreaCode],1) = "N" then "North" else if Text.Start([AreaCode],1) = "W" then "West" else "London" )If anyone else is doing something similar, I would note that I had issues with putting the single letter statements first as it would lump the double letter regions into the same one. For example, if I put North first, it would lump North-West into the same region.
goncalogeraldes helped me figure out a solution using nested if statements 🙂
For anyone else struggling, here's an example of what I used:
= Table.AddColumn(#"Renamed Columns3", "Region", each
if Text.Start([AreaCode],2) = "SW" then "South-West" else /* for conditions where you need the first 2 letters */
if Text.Start([AreaCode],2) = "SE" then "South-East" else
if Text.Start([AreaCode],2) = "BR" then "Bromley" else
if Text.Start([AreaCode],2) = "WC" then "West-Central" else
if Text.Start([AreaCode],2) = "EC" then "East-Central" else
if Text.Start([AreaCode],2) = "NW" then "North-West" else
if Text.Start([AreaCode],1) = "E" then "East" else /* for conditions where you only need the first letter */
if Text.Start([AreaCode],1) = "N" then "North" else
if Text.Start([AreaCode],1) = "W" then "West"
else "London" )
If anyone else is doing something similar, I would note that I had issues with putting the single letter statements first as it would lump the double letter regions into the same one. For example, if I put North first, it would lump North-West into the same region.