Sam, I may be oversimplfying, or perhaps this approach is not robust, but can you use a Group By to collect the direct reports in a comma-delimited string, then split by delimiter into
rows (if it's reliable that the order is maintained) to spit them out? If that's reliable, then the Add Index will finish it off.
If I have a table Emps with two columns Manager and Employee, I can use this M code (mostly generated through the UI):
let
Source = Emps,
#"Replaced Value" = Table.ReplaceValue(Source,"","TOP",Replacer.ReplaceValue,{"Manager"}), // my CEO had a blank for the "manager"
#"Grouped Rows" = Table.Group(#"Replaced Value", {"Manager"}, {{"Directs", each Text.Combine([Employee], ","), type nullable text}}),
#"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Grouped Rows", {{"Directs", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Directs"),
#"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Directs", type text}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type)
in
#"Added Index"
If this helps you, great! But I don't claim to know exactly what the maq visual requires as input. As they used to say, ymmv.
------------------------------
Amon Seagull
McKinney
------------------------------
Original Message:
Sent: May 24, 2022 11:12 PM
From: Sam Duval
Subject: Automated Organization Chart
Hopefully someone here can help me. I have been asked to create an automated org chart via active directory as my source system.
I have power automate script thay loads all the required data into SQL for me to use in power bi.
The problem I'm facing is trying to use the maq org chart visual, it requires the Id numbers to be in decending order. So ceo is #1 and their direct reports start at 2 and go from there. Then their direct reports are numbered greater than them and so on. The problem I'm stuck on is how do I create this hierarchy in the correct order, so that a manager is always a lower number than those who report to them.
I'm thinking I have to loop through every employee with power automate and get direct reports and assign an auto incrementing variable. Please tell me there's a better option