Power Query M - Classify Shape Color Function
Description
This Power Query M function, classifyShapeColor, categorizes shapes based on shape and color values provided, allowing users to create a new column in Power Query Editor for classification within a table.
Power Query M - Classify Shape Color Function
Tool: Code Generator
Created: 05/01/2024
Prompt
if formaTrimmed = "star" and culoareTrimmed = "purple" then "Purple Star"
else if formaTrimmed = "star" and culoareTrimmed = "black" then "Black Star"
else if formaTrimmed = "square" and culoareTrimmed = "green" then "Green Square"
else if formaTrimmed = "circle" and culoareTrimmed = "blue" then "Blue Circle"
else "null"
/*
Function: classifyShapeColor
This function takes two parameters formaTrimmed and culoareTrimmed and returns a corresponding classification based on certain conditions.
Parameters:
formaTrimmed (text): The shape value trimmed.
culoareTrimmed (text): The color value trimmed.
Returns:
text: The classification based on the conditions provided.
*/
classifyShapeColor = (formaTrimmed as text, culoareTrimmed as text) =>
let
classification =
if formaTrimmed = "star" and culoareTrimmed = "purple" then "Purple Star"
else if formaTrimmed = "star" and culoareTrimmed = "black" then "Black Star"
else if formaTrimmed = "square" and culoareTrimmed = "green" then "Green Square"
else if formaTrimmed = "circle" and culoareTrimmed = "blue" then "Blue Circle"
else "null"
in
classification
Usage Example:
Assuming you have a table named "Shapes" with columns "formaTrimmed" and "culoareTrimmed", you can apply this function to create a new column "Classification" using Power Query Editor:
- Go to Power Query Editor.
- Select the table "Shapes".
- Click on "Add Column" -> "Custom Column".
- Enter a new column name, e.g., "Classification".
- Input the formula
classifyShapeColor([formaTrimmed], [culoareTrimmed])
. - Click "OK" to create the new column with the classification results based on the conditions defined in the function.
More Code Generators
Apache Flink Code GeneratorApache Pig Code GeneratorAzure Data Factory Code GeneratorC/C++ Code GeneratorCouchDB Code GeneratorDAX Code GeneratorExcel Code GeneratorFirebase Code GeneratorGoogle BigQuery Code GeneratorGoogle Sheets Code GeneratorGraphQL Code GeneratorHive Code GeneratorJava Code GeneratorJavaScript Code GeneratorJulia Code GeneratorLua Code GeneratorM (Power Query) Code GeneratorMATLAB Code GeneratorMongoDB Code GeneratorOracle Code GeneratorPostgreSQL Code GeneratorPower BI Code GeneratorPython Code GeneratorR Code GeneratorRedis Code GeneratorRegex Code GeneratorRuby Code GeneratorSAS Code GeneratorScala Code GeneratorShell Code GeneratorSPSS Code GeneratorSQL Code GeneratorSQLite Code GeneratorStata Code GeneratorTableau Code GeneratorVBA Code Generator