Created
June 26, 2019 21:08
-
-
Save alberto1el/9005f223b0470474b5531118aa830e0c to your computer and use it in GitHub Desktop.
A PowerBI formula to handle polymorphic relationships using conditional columns (MySQL source)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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