Skip to content

Instantly share code, notes, and snippets.

@bjulius
Created October 6, 2023 23:01
Show Gist options
  • Save bjulius/bcd378438942cbae69a5f0e6a177fcfa to your computer and use it in GitHub Desktop.
Save bjulius/bcd378438942cbae69a5f0e6a177fcfa to your computer and use it in GitHub Desktop.
M Code for Named Colors Table w/ Transparent Option in Power BI
let
Source = Web.BrowserContents("https://www.w3schools.com/cssref/css_colors.php"),
ExtractFromHTML = Html.Table(Source, {{"Column1", ".colornamespan *"}, {"Column2", ".colorhexspan *"}, {"Column3", ".linktocolormixerdiv *"}, {"Column4", ".linktocolorpickerdiv *"}}, [RowSelector=".colorbox"]),
RemoveCols = Table.RemoveColumns(ExtractFromHTML,{"Column3", "Column4"}),
RenameCols = Table.RenameColumns(RemoveCols,{{"Column1", "NamedColor"}, {"Column2", "HexCode"}}),
TransparentRow = #table({"NamedColor", "HexCode"}, {{"Transparent", "#FFFFFF00"}}),
AppendTransparent = Table.Combine( {RenameCols, TransparentRow}),
Addndex = Table.AddIndexColumn(AppendTransparent, "Index", 1, 1, Int64.Type),
Reorder = Table.ReorderColumns(Addndex,{"Index", "NamedColor", "HexCode"}),
ChangeTypes = Table.TransformColumnTypes(Reorder,{{"NamedColor", type text}, {"HexCode", type text}})
in
ChangeTypes
// Coded by Brian Julius
// Creates table of all named colors recognized by Power BI using the CSS reference information from the w3schools.com website
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment