Forum Discussion
Set column type while expanding from merged query
- 8 years ago
I am working with Excel using Excel.Workbook(Web.Contents())
In matter of fact the type doesn't matter untill I don't lose the zeros. Like 0003 > 3, 0005 > 5.
MarcelBeug the change of the data type occurs while expanding and zeros are lost. I guess there's nothing to get them back.
It is very nice how you values remain their zeros while their type is a number.My temporary solution was to change the type to a number everywhere and duplicate the column with type text in the table that I visualize. Works pretty good but it would be better if that was not necessary.
Thank you both!
Here's a blog post I wrote on this problem showing how to solve it in M:
https://blog.crossjoin.co.uk/2017/09/25/setting-data-types-on-nested-tables-in-m/
HTH,
Chris
Still it is starnge that those text values are transfomed to numbers.
Even if the column would be typed as number, then still the merge doesn't effect the actual values (which are texts with leading zeroes).
So there must be something else, before the merge, that cause the values to be transformed to numbers.
Coincidentally I published a video this morning with an example of grouping tables, illustrating that the default code would change data types to any, and how that can be correccted before the tables are expanded.
The fragment starts at 4:08; keep watching until at least 5:50.
Back to your case, here is some example data:
Query Shifts:
#table(type table[ID =Int64.Type, Personnel Number = Int64.Type],{{1, "0333"},{2, "0555"},{3, "0888"}})
Query Table1:
= #table({"Key","Person"},{{11, 1},{12, 2},{13, 3}})
Query Merge1:
let
Source = Table.NestedJoin(Table1,{"Person"},Shifts,{"ID"},"Shifts",JoinKind.LeftOuter),
#"Expanded Shifts" = Table.ExpandTableColumn(Source, "Shifts", {"Personnel Number"}, {"Personnel Number"})
in
#"Expanded Shifts"
Result from query Merge1: