Forum Discussion
Calculated column that checks whether a value in another column exists based on third value
- 3 years ago
You want to add a column for each month on your dataset is that it?
In this case you have two options:
Power Query
- Group your table by route and location
- Select all rows in the option of aggregation
- Add a custom step that create a list based on month
Table.ToList (Table.SelectColumns ( [TableList], "Month"))- Do merge with the Source step by location and route
- Expand the list from the table
- Add a custom step with the following code:
= List.Accumulate({"Jan", "Feb", "Mar", "Apr", "May", "June", "July","Aug", "Sep", "Oct", "Nov", "Dec"}, #"Expanded Added Custom1", (state, current) => Table.AddColumn(state, current, each if List.Contains( [Added Custom1.Custom], current) then "YES" else "NO"))Result below:
Calculated Columns in DAX
For each month add the following column sintax:
July = VAR routeselection = 'Table (2)'[Route] VAR locationselection = 'Table (2)'[Location] RETURN IF ( "July" IN SELECTCOLUMNS ( FILTER ( ALL ( 'Table (2)'[Route], 'Table (2)'[Month] ), 'Table (2)'[Route] = routeselection && 'Table (2)'[Location] = locationselection ), "Months", 'Table (2)'[Month] ), "YES", "NO" )You need to replace the name of the Month and the text after the IF
See attach PBIX file.
- Group your table by route and location
You want to add a column for each month on your dataset is that it?
In this case you have two options:
Power Query
- Group your table by route and location
- Select all rows in the option of aggregation
- Add a custom step that create a list based on month
Table.ToList (Table.SelectColumns ( [TableList], "Month"))
- Do merge with the Source step by location and route
- Expand the list from the table
- Add a custom step with the following code:
= List.Accumulate({"Jan", "Feb", "Mar", "Apr", "May", "June", "July","Aug", "Sep", "Oct", "Nov", "Dec"},
#"Expanded Added Custom1", (state, current) =>
Table.AddColumn(state, current, each if List.Contains( [Added Custom1.Custom], current) then "YES" else "NO"))
Result below:
Calculated Columns in DAX
For each month add the following column sintax:
July =
VAR routeselection = 'Table (2)'[Route]
VAR locationselection = 'Table (2)'[Location]
RETURN
IF (
"July"
IN SELECTCOLUMNS (
FILTER (
ALL ( 'Table (2)'[Route], 'Table (2)'[Month] ),
'Table (2)'[Route] = routeselection
&& 'Table (2)'[Location] = locationselection
),
"Months", 'Table (2)'[Month]
),
"YES",
"NO"
)
You need to replace the name of the Month and the text after the IF
See attach PBIX file.
Thank you!
The second method worked.
The first I didn't try because it's a calculated table and I have no access to the table transformations you show on the printscreens.