2016-04-29 4 views
1

このその他の電力クエリquestion and answerは、文字区切りテキストファイルを列文字カウント幅に基づいて列に分割するソリューションを提供します。電力クエリ - 可変フィールド長で列を分割する - NULL値を考慮する

しかし、それはヌルを説明しません。ヌル値が検出されると、右側の列の1つでエラーが発生します。私はまさに何が起こっているのか正確に言うことはできません。エラーが

An error occurred in the ‘SplitText’ query. Expression.Error: The 'count' argument is out of range. 

あるスプリット関数のコードは次のとおりです。

each SplitText([Column1], {4, 2, 5, 3}) 

私はExcelを使用しています:

let 
    SplitText = (text, lengths) => 
    let 
     LengthsCount = List.Count(lengths), 
     // Keep track of the index in the lengths list and the position in the text to take the next characters from. Use this information to get the next segment and put it into a list. 
     Split = List.Generate(() => {0, 0}, each _{0} < LengthsCount, each {_{0} + 1, _{1} + lengths{_{0}}}, each Text.Range(text, _{1}, lengths{_{0}})) 
    in 
     Split, 
    // Convert the list to a record to 
    ListToRecord = (text, lengths) => 
    let 
     List = SplitText(text, lengths), 
     Record = Record.FromList(List, List.Transform({1 .. List.Count(List)}, each Number.ToText(_))) 
    in 
     Record 
in 
    ListToRecord 

次に、あなたのテーブルには、この式を使用するカスタム列を追加2010 64ビット版とパワークエリーバージョン:2.29.4217.1861

ヌルを考慮してこれを変更するにはどうすればよいですか?

答えて

1
Split = List.Generate(() => {0, 0}, each _{0} < LengthsCount, each {_{0} + 1, _{1} + lengths{_{0}}}, each try Text.Range(text, _{1}, lengths{_{0}}) otherwise null) 
関連する問題