Forum Discussion
Unroll data from self-referencing table
Hi,
I am a bit stuck on how to to handle some data in Power BI. I am quite new to it so I don’t even know if what I want to do is possible or not… my googling didn’t come up with anything successful, but maybe I am not using the right terms.
So I have two tables, “rule” and “thing”. The table “rule” references lines in the table “thing” as well as in itself :
rule | ||||
name | action | target | ||
rule1 | do thing | thing1 | ||
rule1 | do thing | thing2 | ||
rule2 | do thing | thing3 | ||
rule2 | do rule | rule1 | ||
rule3 | do rule | rule2 | ||
|
|
| ||
thing |
| |||
name | parameter |
| ||
thing1 | x=y |
| ||
thing2 | z=y |
| ||
thing3 | z+y |
| ||
What I want to do is being able to easily see which things are used in which rules. To do that, I created a new column in the table “rule” which goes like :
= Table.AddColumn(…, "LinkedThings", each if [#"action"]="do thing" then [target] else "null")
So I now have a “rule” table that looks like that :
rule | |||
name | action | target | LinkedThings |
rule1 | do thing | thing1 | thing1 |
rule1 | do thing | thing2 | thing2 |
rule2 | do thing | thing3 | thing3 |
rule2 | do rule | rule1 | null |
rule3 | do rule | rule2 | null |
And I added a relationship between rule.LinkedThings and thing.name so that I could see my data like that :
rule.name | thing.name |
rule1 | thing1 |
rule1 | thing2 |
rule2 | thing3 |
The problem here is that it doesn’t work for nested rules, for example rule2 is calling rule1 which calls thing1, so I should see that thing1 is linked to rule2. My end-goal visualization would be something like that :
rule.name | thing.name |
rule1 | thing1 |
rule1 | thing2 |
rule2 | thing3 |
rule2 | thing1 |
rule3 | thing3 |
rule3 | thing1 |
rule3 | thing2 |
Of course there is no limitation to the depth of rules references, I thought about creating a new column in the same idea that I did “rule.LinkedThings” and then having a second “rule” table and cross-reference between these but it’s quite ugly, and I would need X table for X depth…
I also tried to look for a function that I could used in a new column that would recursively search in its own table but to no avail.
I would be really happy for any help provided, I might also use the totally wrong tool for what I want to do, as I said I’m really new to Power BI so don’t hesitate to tell me if that’s the case 😊
Thank you and have a nice day !
2 Replies
- v-xiaotangCommunity Support
Hi arbr
Thanks for reaching out to us.
Could you please provide more details according to the picture below,
Best Regards,
Community Support Team _Tang
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.
- arbrNew Member
Hi v-xiaotang !
In this example the outcome of rule2 would be thing3, thing2 and thing1. The outcome of rule3 would be exactly the same as rule2 which obviously doesn't make any sense, but I tried for this example to create something the most simple possible while including enough to understand my issue.
In my real dataset I have hundreds of rules with thousands of "things" with lots of imbrication...
Thanks to you I realized the last table I inserted is wrong, so that would be the real end-goal visualization :
rule.name
thing.name
rule1
thing1
rule1
thing2
rule2
thing3
rule2
thing2
rule2
thing1
rule3
thing3
rule3
thing2
rule3 thing1 Regards