Forum Discussion
Very quick 'IF function' question
- 1 year ago
If you only have a few accounts to add the percentage, the the formula provided by PwerQueryKees should be sufficient.
If you have a large number of accounts to consider, you would be better off creating a table of accounts vs reponsible percentages which you could then refer to for your Custom column.
Paste the below code into the Advanced Editor to see how that would work. In your real data, you would create the Responsible and Data tables separately.
let //sample table of responsibility #"Responsible Percent" = Table.Buffer(Table.FromRecords({ [Account="B1234", Percent=0.25], [Account="B5678", Percent=0.50]}, type table[Account=text, Percent=Percentage.Type])), //sample data table Source = Table.FromRecords({ [Account="B1234"], [Account="B5678"], [Account="A9876"], [Account="A1579"], [Account="C1234"] },type table[Account=text]), //Add responsible percent column per account #"Added Custom" = Table.AddColumn(Source, "Responsible Percentage", each try Table.SelectRows(#"Responsible Percent",(r)=> r[Account]=[Account])[Percent]{0} otherwise 0, Percentage.Type) in #"Added Custom"Responsible Table
Results
Hello,
Apologies for the delay in resonding.
I think your answer is the best way forward for me as it means I can add more accounts to that list every year.
With that said I have got myself in a tangle trying to follow your answer.
I have now created a separate table in a separate excel spreadhseet with the account name and it's corresponding percentage.
| Account | Percent |
| B0429BALT | 25.00% |
| B0429BAAB | 25.00% |
| B0507NALB4730024A | |
| B0429BARBT | 50.00% |
| B0429BA2100128 | |
| B0429BASBT | 50.00% |
| B0429BAPE | 100.00% |
| B2429BWMB | 100.00% |
That is now saved as a separate spreadhseet.
and now I'm stuck.
What code am I entering? How do I get this spreadsheet into my power query?
In Excel, you would
- Select a cell in the table
- Navigate Data=>Get & Transform=>From Table/Range
And then in your main query, you would refer to it by the name you see in either side panel that refers to that query (replacing #"Responsible Percent"). Or you could just rename that query #"Responsible Percent".