Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello,
I'm still fairly new to Power BI and I'm trying to add a new column thats based on the Tracking column.
Basically I'm not sure how to properly code the following:
If the length is =6 I would like to add "A1S1"
If the length is =8 add "S1"
If the length is =10 keep as is
I normally do this in an offline Excel doc which I use a simple If/Then and Concat but with Power BI having a different syntax I'm not sure how to proceed.
I should also mention that the excel doc is pulled from our ERP system which makes it not possible to add this formula to the excel doc.
Thank you!
Lucas
Solved! Go to Solution.
Hi,Greg_Deckler .thanks for your concern about this issue.
Your answer is excellent!
And I would like to share some additional solutions below.
Hello,@QELucas .I am glad to help you.
I hope you find my test below helpful, I have uploaded my test file so you can download it and see the steps in detail.
Here is my test data.
Use M code
In Power Query:
if Text.Length([Tracking])=6 then [Tracking] &"A1S1"
else if Text.Length([Tracking])=8 then [Tracking] &"S1"
else if Text.Length([Tracking])=10 then [Tracking]
else [Tracking]&"Error"
Use DAX code
In Power BI
use IF function or SWITCH function:
Create a calculate column:
C_RFT Tracking =
VAR LengthOfTarcking = LEN([Tracking])
RETURN
IF(
LengthOfTarcking = 6,
[Tracking] & "A1S1",
IF(
LengthOfTarcking = 8,
[Tracking] & "S1",
IF(
LengthOfTarcking = 10,
[Tracking],
[Tracking] & "Error"
)
)
)
C_switch Tracking =
VAR LengthOfTarcking = LEN([Tracking])
RETURN
SWITCH(TRUE(),
LengthOfTarcking =6, [Tracking] & "A1S1",
LengthOfTarcking = 8,[Tracking] & "S1",
LengthOfTarcking = 10,[Tracking],
[Tracking] & "Error"
)
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,Greg_Deckler .thanks for your concern about this issue.
Your answer is excellent!
And I would like to share some additional solutions below.
Hello,@QELucas .I am glad to help you.
I hope you find my test below helpful, I have uploaded my test file so you can download it and see the steps in detail.
Here is my test data.
Use M code
In Power Query:
if Text.Length([Tracking])=6 then [Tracking] &"A1S1"
else if Text.Length([Tracking])=8 then [Tracking] &"S1"
else if Text.Length([Tracking])=10 then [Tracking]
else [Tracking]&"Error"
Use DAX code
In Power BI
use IF function or SWITCH function:
Create a calculate column:
C_RFT Tracking =
VAR LengthOfTarcking = LEN([Tracking])
RETURN
IF(
LengthOfTarcking = 6,
[Tracking] & "A1S1",
IF(
LengthOfTarcking = 8,
[Tracking] & "S1",
IF(
LengthOfTarcking = 10,
[Tracking],
[Tracking] & "Error"
)
)
)
C_switch Tracking =
VAR LengthOfTarcking = LEN([Tracking])
RETURN
SWITCH(TRUE(),
LengthOfTarcking =6, [Tracking] & "A1S1",
LengthOfTarcking = 8,[Tracking] & "S1",
LengthOfTarcking = 10,[Tracking],
[Tracking] & "Error"
)
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@QELucas Why is this posted like 6 or 7 times?
Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882
Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
Apologies for the multiple posts, not sure what happened there.
I was able to use the Excel to DAX Translation - Microsoft Fabric Community with great success and my column is populating correcty.
Thank you for the resource!
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
63 | |
62 | |
52 | |
39 | |
24 |
User | Count |
---|---|
84 | |
57 | |
45 | |
42 | |
37 |