March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
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.
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
Hi @YesP
Try this:
VAR SecondLetter =
MID ( TableName[ColumnName], 2, 1 )
RETURN
SWITCH (
SecondLetter,
"A", "Administrative",
"L", "Liability",
"O", "Operations",
"U", "Utilities"
)
Proud to be a Super User!
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" )
@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,
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.
Proud to be a Super User!
@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?
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.
Proud to be a Super User!
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 )
Proud to be a Super User!
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
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
114 | |
76 | |
57 | |
52 | |
44 |
User | Count |
---|---|
168 | |
116 | |
63 | |
57 | |
50 |