Forum Discussion
New Conditional Column from Two Other Columns in M
- 6 months ago
This should solve your issue.
= Table.AddColumn(previousStep, "ConditionalColumn", each if [Number Category] = 3 and [Pet Type] = "Dog" then "Adopted" else [Pet Type], type text)
jgeddes thank you for the reply! It did not quite work. It did create a new column and replicated the text from the pet type column, however, the new "Adopted" title is not incorporated for some reason. All the orange in the below graph meets the criteria for "dog" and "3" but it still has the old tag of "dog".
If the code provided gave you a column result similar to
We can assume that the M code worked as intended.
Can you confirm that you are using the new "conditional column" in the chart you shared?
- UnearthlyFalcon6 months agoAdvocate I
jgeddes Yes, I removed the old column and added the new "conditional column" to the graph. I also inserted a new table visual to verify and the "adopted" is not there, it is "dog". I'm not sure what is wrong. In my data, the pet type is another conditional column, but it is earlier in the applied steps. Is this throwing it off?
- jgeddes6 months agoSuper User
An earlier conditional step should not matter as long as the conditional column we created references the immediate previous step.
If the "Conditional Column" is loaded into the report, and you can view the correct data in the table view, I cannot explain why you are getting the result you are.
I will share my pbix file to see if you can compare between and find the issue.- UnearthlyFalcon6 months agoAdvocate I
I needed to change the column type to text for the original two columns, that fixed it!