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.
Hi
I trying to create a custom column based on how the value in column 'Project_ID' begins. The Project_ID is a whole number, it does not contain any text values. I wanted to flag any projects that are from our legancy system, projects from the old system begin with '11' plus I need to test if a few of them are still active but checking a field called 'Status'; which is a text field, shows these jobs are 'Active' or not; as smal number are still valid. So if I can indentify which project is from the Legacy system I will populate a custom column; e.g. LegacyChecker, with the value 'Legacy'. I was then planninng to then filter out thoese that have a value of 'Legacy'. The conditional formating in powerquery has 'begins with', but this only applies to text. I am wanting to do this work at the powerquery or Query Editor stage rather then the front end; but will take advise on best practice.
Example data:
Project ID Status LegacyChecker
1123457 Active
1155447 Active
1137897 Closed Legacy
1147899 Closed Legacy
Many thanks
Chris
Solved! Go to Solution.
Hi @ccarpent ,
We can create a custom column like that to work on it.
if Text.StartsWith(Number.ToText([Project ID]),"11") and [Status] = "Closed" then "Legacy" else null
M code for your reference.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ0MjYxNVfSUXJMLsksS1WK1QEJmpqamGAIGptbWIIEnXPyi1NToIImQEFLJMFYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Project ID" = _t, Status = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Project ID", Int64.Type}, {"Status", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "LegacyChecker", each if Text.StartsWith(Number.ToText([Project ID]),"11") and [Status] = "Closed" then "Legacy" else null)
in
#"Added Custom"
Hi @ccarpent ,
We can create a custom column like that to work on it.
if Text.StartsWith(Number.ToText([Project ID]),"11") and [Status] = "Closed" then "Legacy" else null
M code for your reference.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ0MjYxNVfSUXJMLsksS1WK1QEJmpqamGAIGptbWIIEnXPyi1NToIImQEFLJMFYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Project ID" = _t, Status = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Project ID", Int64.Type}, {"Status", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "LegacyChecker", each if Text.StartsWith(Number.ToText([Project ID]),"11") and [Status] = "Closed" then "Legacy" else null)
in
#"Added Custom"
Frank
Thats great thanks for your help.
Chris
If text, LEFT('Table'[Project ID],2) = "11" or if it is a number maybe LEFT('Table'[Project ID] & "",2)
Greg
Thanks for the formula, now that I have looked back over the table there is actually bit more involved, my mistake for not realising there is also some key extra data. There are other Project ID's that do not start with '11' but they need to be included as they are not legacy data/cases. I just wanted to exclude cases thoses that started with '11' and status <> Active or more accuartly their end date; Dates_2, is in the future.
I did come up with a formula, based around what you posted, I broke my solution down into more manageable chunks to get it to work. Probally not my best work:
I did come across some M Language for 'List.AllTrue' and 'Text.StartsWith', I was tryiing combine these functions with IF, AND and OR to create a single calculation; that was the theory.
Chris
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
102 | |
53 | |
21 | |
12 | |
12 |