Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and a 50 percent discount on exams.
Get startedEarn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hello
I need to make this new column ProductType for what it asks me and I do not know what function / functions to use, thanks in advance:
Product Type. It will store the type of product being marketed. Be Meat for those products whose Variety Code start with C, Fish for those products whose Variety Code start with P y Fruits and Vegetables for those products whose Code of Variage start with F.
Solved! Go to Solution.
You can do either in DAX or power query. I prefer Power Query.
DAX, you can do with "Switch" and "Contains", "ContainsString"
DAX - Add new Column:
Product Type Column =
var _pt_1stChar = LEFT('Table'[Variety Code], 1)
RETURN SWITCH(
TRUE(),
_pt_1stChar = "C", "Meat",
_pt_1stChar = "P", "Fish",
_pt_1stChar = "F", "Fruits & Vegetables"
)
DAX - Add new measure:
Product Type Measure =
var _pt_1stChar = LEFT(SELECTEDVALUE('Table'[Variety Code]), 1)
RETURN SWITCH(
TRUE(),
_pt_1stChar = "C", "Meat",
_pt_1stChar = "P", "Fish",
_pt_1stChar = "F", "Fruits & Vegetables"
)
Power query, you can do with "Text.StartsWith" or "Text.Contains" per your needs and Conditional column:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wck4EA6VYnWilZAQzIB9JvCAfwXYrggEwN62oCEkgFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Variety Code" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Variety Code", type text}}),
#"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Product Type",
each if Text.StartsWith([Variety Code], "C", Comparer.OrdinalIgnoreCase) then "Meat"
else if Text.StartsWith([Variety Code], "P", Comparer.OrdinalIgnoreCase) then "Fish"
else if Text.StartsWith([Variety Code], "F", Comparer.OrdinalIgnoreCase) then "Fruits & Vegetables" else null)
in
#"Added Conditional Column"
I dont know spanish, sorry, I used some text for Variety code to get the code for you.
You can do either in DAX or power query. I prefer Power Query.
DAX, you can do with "Switch" and "Contains", "ContainsString"
DAX - Add new Column:
Product Type Column =
var _pt_1stChar = LEFT('Table'[Variety Code], 1)
RETURN SWITCH(
TRUE(),
_pt_1stChar = "C", "Meat",
_pt_1stChar = "P", "Fish",
_pt_1stChar = "F", "Fruits & Vegetables"
)
DAX - Add new measure:
Product Type Measure =
var _pt_1stChar = LEFT(SELECTEDVALUE('Table'[Variety Code]), 1)
RETURN SWITCH(
TRUE(),
_pt_1stChar = "C", "Meat",
_pt_1stChar = "P", "Fish",
_pt_1stChar = "F", "Fruits & Vegetables"
)
Power query, you can do with "Text.StartsWith" or "Text.Contains" per your needs and Conditional column:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wck4EA6VYnWilZAQzIB9JvCAfwXYrggEwN62oCEkgFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Variety Code" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Variety Code", type text}}),
#"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Product Type",
each if Text.StartsWith([Variety Code], "C", Comparer.OrdinalIgnoreCase) then "Meat"
else if Text.StartsWith([Variety Code], "P", Comparer.OrdinalIgnoreCase) then "Fish"
else if Text.StartsWith([Variety Code], "F", Comparer.OrdinalIgnoreCase) then "Fruits & Vegetables" else null)
in
#"Added Conditional Column"
I dont know spanish, sorry, I used some text for Variety code to get the code for you.
A switch statement ought to do it.
ProductType =
SWITCH(
TRUE(),
VarietyCode = "C", "Meat",
VarietyCode = "P", "Fish",
VarietyCode = "F", "Fruits & Vegetables"
)
User | Count |
---|---|
96 | |
87 | |
78 | |
72 | |
68 |
User | Count |
---|---|
113 | |
105 | |
84 | |
65 | |
64 |