Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
TM_Evan
Helper I
Helper I

Creating Slice by using left 2 letters of column values

I am attempting to create a slice for the left two characters of an existing order name field in SQL.

 

Example - FL-XX-X-XXXX would return FL

                 GA-xx-x-xxxx would return GA

 

This slice would be useful to toggle State for reports.

 

From what I thought I understand, Dax LEFT would be the way to go but I am not getting it right.

I am attempting to create a slice using the following steps

1) drag table to Page

2) Select Slicer from visualizer (This displays ALL existing order numbers and only way to slice is individual order number

3) Select New Measure and enter 'SliceNumber = LEFT(<table>,2)

Receive error - The syntax for 'table' is incorrect.

 

I am wondering if I need to add some grouping function to this measure but I am new to this and hopeful that the community may be able to assist me.

 

Thank you

 

 

 

2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

LEFT takes a text value for its first parameter, not a table. Create a calculated column perhaps like:

 

Column = LEFT([column],2)

Then you can just use that column in your slicer.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Hi @TM_Evan,


I think you put these formula in a measure, right?

You can use calculate column to store these formula, then drag this calculated column to slicer.

 

In addition, if you only want to return the left 2 characters of chosen item, you can try to use below formula:

 

Selected 2 character = 
var selected= if(HASONEVALUE('Table'[Column]),VALUES('Table'[Column]),BLANK())
return
If(selected<>BLANK(),LEFT(selected,2))

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

LEFT takes a text value for its first parameter, not a table. Create a calculated column perhaps like:

 

Column = LEFT([column],2)

Then you can just use that column in your slicer.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thank you for the quick reply.

 

I think I understand what I am doing wrong.  I am creating this BI report from 2 joined table.  I am finding the measurement in the wrong table.  Could you please clarify to me the syntax?  I am using

[Name of Measurement] = LEFT ('Schema Table'[Column],2)

Still not working right.  Please continue pointing me in the right direction.  Thank you for all your help.

Hi @TM_Evan,


I think you put these formula in a measure, right?

You can use calculate column to store these formula, then drag this calculated column to slicer.

 

In addition, if you only want to return the left 2 characters of chosen item, you can try to use below formula:

 

Selected 2 character = 
var selected= if(HASONEVALUE('Table'[Column]),VALUES('Table'[Column]),BLANK())
return
If(selected<>BLANK(),LEFT(selected,2))

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

I discovered what I did wrong from the initial reply.  I failed to Add column and THEN use the DAX expression.  Once I did that I was able to use the Slice in the exact way that I needed it.  Thank you for all this excellent input.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.