Skip to content

Instantly share code, notes, and snippets.

@alberto1el
Created June 26, 2019 21:08
Show Gist options
  • Select an option

  • Save alberto1el/9005f223b0470474b5531118aa830e0c to your computer and use it in GitHub Desktop.

Select an option

Save alberto1el/9005f223b0470474b5531118aa830e0c to your computer and use it in GitHub Desktop.
A PowerBI formula to handle polymorphic relationships using conditional columns (MySQL source)
let
Source = MySQL.Database("127.0.0.1:33060", "dbname", [ReturnSingleDatabase=true]),
table = Source{[Schema="dbname",Item="location_logs"]}[Data],
#"Added Conditional Column1" = Table.AddColumn(table, "location_name",
each if [locatable_type] = "condition_one" then (
let conditionOneID = [locatable_id] in
Table.SelectRows(#"dbname source_table_one", each [id] = conditionOneID)
){0}[name]
else if [locatable_type] = "condition_two" then (
let conditionTwoID = [locatable_id] in
Table.SelectRows(#"dbname source_table_two", each [id] = conditionTwoID)
){0}[name]
else
"IN TRANSIT"
)
in
#"Added Conditional Column1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment