- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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 0
if [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 null
2. 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi @YesP
Try this:
VAR SecondLetter =
MID ( TableName[ColumnName], 2, 1 )
RETURN
SWITCH (
SecondLetter,
"A", "Administrative",
"L", "Liability",
"O", "Operations",
"U", "Utilities"
)
Dane Belarmino | Microsoft MVP | Proud to be a Super User!
Did I answer your question? Mark my post as a solution!
"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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" )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

@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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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.
Dane Belarmino | Microsoft MVP | Proud to be a Super User!
Did I answer your question? Mark my post as a solution!
"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

@danextian Thank you but I tried the first formule without SelectedValue but it does not works because my Datasource is a DirectQuery Semantic model storage in a different software.I think that I can not create a calculate column in Power BI using a DirectQuery Semantic model as Data source. Please any other sugestion how I can add the Description Column in a filter?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

If it doesn't work because of Direct Query limitation, you can try creating a column in the query editor using first by adding a column that extracts the second letter and another conditional column to return the description. I've tested the steps below using MS SQL and they didn't break query folding. If this doesn't work, I would suggest to import the code column instead of DQ or create a view in SQL instead.
Dane Belarmino | Microsoft MVP | Proud to be a Super User!
Did I answer your question? Mark my post as a solution!
"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi @YesP
It appears you are creating a measure and not a calculated column. You cannot directly access a column in a measure (unless in a table expression or when filtering) without aggregating it beforehand. Use this:
MID ( SELECTEDVALUE ( TableName[ColumnName] ), 2, 1 )
Dane Belarmino | Microsoft MVP | Proud to be a Super User!
Did I answer your question? Mark my post as a solution!
"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi @danextian , This formule works great! you are awesome! I want to add a condition, if a Code start with C and lenght =3 then

Helpful resources
Subject | Author | Posted | |
---|---|---|---|
05-23-2024 10:14 AM | |||
08-16-2024 01:37 AM | |||
04-14-2024 01:41 PM | |||
06-13-2024 08:47 AM | |||
06-12-2023 11:21 AM |
User | Count |
---|---|
123 | |
103 | |
85 | |
49 | |
46 |