Forum Discussion
Create a Conditional Measure working with a Direct Query Semantic Model
Hi,
I am working with a Semantic Model so I am not able to use the Transform Data option from Power BI.
In the Semantic Model I have a column Code and I want to create a column Code Desccription. This new column is based in the second letter of the Code: For instance, if Code is CAB, second letter is A then Code Description will be Administrative. I want to use this Code Description in a Filter to create visualization with this Code Description column. Please your help!
Thanks,
10 Replies
- YesP
Helper I
- YesP
Helper I
danextian It works! How I can use it in a filter? I try to use this new measure Description in a filter but it does not work. It just work in a table as long as I use the Code column as well.
I want the User be able to select the description in a filter and see all their transactions related to the description selected.
Please your help.
Thanks,
- danextian
Super User
Create a calculated column instead. Measures don't have row context and are evaluated based on the other dimensions added to a viz so it cannot be used as a dimension or in a slicer. The first formula without SELECTEDVALUE creates a calculated column.
- YesP
Helper I
Hi danextian , How I can add to this formule the following syntax:
If the column Code start with C and lenght=3 then secondLetter= "A","Administrative",.... the rest of the formule lines below.
VAR SecondLetter = MID ( TableName[ColumnName], 2, 1 ) RETURN SWITCH ( SecondLetter, "A", "Administrative", "L", "Liability", "O", "Operations", "U", "Utilities" )
- AnonymousNot applicable
Thanks for the reply from danextian , please allow me to add some more information:
Hi YesP ,Here are the steps you can follow:
1. In Power Query – Add Column – Custom Column.
if Text.Start([Code], 1)="C" and Text.Length([Code])=3 then 1 else 0if [Custom]=1 and Text.Middle([Code], 1, 1)="A" then "Administrative" else if [Custom]=1 and Text.Middle([Code], 1, 1)="L" then "Liability" else if [Custom]=1 and Text.Middle([Code], 1, 1)="O" then "Operations" else if [Custom]=1 and Text.Middle([Code], 1, 1)="U" then "Utilities" else null2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly