Forum Discussion
create alias table
- 8 years ago
I've tweaked the fnVLookup to just do a text match search and pick the first entry by an order.
(lookup_value as any, table_array as table, col_index_number as number, optional array_order_column as number) as any => let /*Provide optional sort column if user didn't */ sortColNo = if array_order_column = null then 0 else array_order_column - 1 , /*Get name of return column */ Cols = Table.ColumnNames(table_array), ColTable = Table.FromList(Cols, Splitter.SplitByNothing(), null, null, ExtraValues.Error), ColName_match = Record.Field(ColTable{0},"Column1"), ColName_return = Record.Field(ColTable{col_index_number - 1},"Column1"), ColName_Sort = Record.Field(ColTable{sortColNo}, "Column1"), /*Find closest match */ SortData = Table.Sort(table_array,{{ColName_Sort, Order.Ascending}}), RenameLookupCol = Table.RenameColumns(SortData ,{{ColName_match, "Lookup"}}), Matches = Table.SelectRows(RenameLookupCol, each Text.Contains(lookup_value, [Lookup])), Return = if Table.IsEmpty(Matches)=true then "#N/A" else Record.Field(Matches{0}, ColName_return) in Return
I would put a category field on your table
There a couple of ways to do this.
1) Create a manual mapping list. This is easy, but doesn't update automatically if they type bad data.
Then merge the mapping with your date lookup the category or create a relationship to the mapping as a lookup table.
2) Use keyworld lookup
I use this function from KenPuls to do vlookup type keywork matches for SSIS package names to get a category in my SSIS dashboard. http://community.powerbi.com/t5/Data-Stories-Gallery/SSIS-Catalog-DB-Dashboard/m-p/244677#M1110
Details of the function post is here.
https://www.excelguru.ca/blog/2015/01/28/creating-a-vlookup-function-in-power-query/
This is more flexible, but can still get it wrong especially if you have a keyworld that can have two possible categories. I use a rank to prioritse which keywords are matched first.
Also try to avoid pie/donuts as they are not good visuals.
Some great details picking the correct visual
https://www.youtube.com/watch?v=-tdkUYrzrio
https://www.sqlbi.com/p/power-bi-dashboard-design-course/
Hey stretcharm, thanks for the shout out, and glad you've found the VLOOKUP function useful. It's recently come up that there is a way faster way to do this though. Oz has a video on this here which you may want to consider: https://www.youtube.com/watch?v=EYgKciBr_dg
I'm thinking it should run faster than my original approach. :)