フィルタのように、特定のものだけのDTを作りたい

UiPath初心者です。

データテーブルをフィルタではなく、
代入で特定のものを絞り込む方法が知りたいです。
下記のような感じで書きたいのですが、
ネット上で探しても良く分かりませんでした。

列:『月度』
対象:『4月度』『4』 の場合、どのように書けば良いでしょうか。

dt=dt.AsEnumerable.Where(Function(r) ????????????(r(“月度”).ToString)).CopyToDataTable

Hi @miwa_yamamoto

You can try this

dt = dt.AsEnumerable.Where(Function(r) r(“Monthly”).ToString = “4*”).CopyToDataTable

4* should cover both 4月度 and 4 cases.

Regards,
Kah Liang

1 Like

ありがとうございます。

別トピになるかも知れませんが、可能ならばもう1つ教えて下さい。

こちらの部分を可能ならば可変としたく、変数にする方法はありますでしょうか。

Hi @miwa_yamamoto

Yes you definitely can.

Just start from creating a variable, let’s say “Month”

dt = dt.AsEnumerable.Where(Function(r) r(“Month”).ToString = Month).CopyToDataTable

You can try to call the variable by pressing ctrl+space at r(“Month”).ToString = HERE

Also, for you information there are many different ways to filter datatable you can learn them here and use different one for different scenario.

Regards,
Kah Liang

1 Like

ご丁寧にありがとうございます。

こちらの部分がよく分からなかったのですが、
これは、robotを実行する中で行う処理ですか。

Oh sorry @miwa_yamamoto that might be confusing.

ctrl+space allows to call out the intelligent panel to assist you. You do this when writing the code.

It is not important in this case, just a tip of using this tool to assist you when you write code.

The important part is to create variable, then put the variable into the code like what you will do when comparing with a String value but just without the double quotes.

Let me know if adding variable into the code works for you. And please mark as solution when everything is solved. Thanks!

Regards,
Kah Liang

1 Like

ありがとうございます。
無事に、変数で作成することが出来ました。

1 Like

@miwa_yamamoto

You’re welcome! and Happy Automation :smile:

1 Like

すみません。
もう少し教えて下さい。
robot実行時に、入力ダイアログ で〇月度 を選択してもらい、それを変数として取得し、
先程の式へ当てはめようとしたのですが、
先述の通り、2パターンの記述存在しており、抽出が片方しか出来ませんでした。

そこで式を
DT=DT.AsEnumerable.Where(Function(r) r(“計上月度”).ToString = Month+“*”).CopyToDataTable

としたのですが、以下のエラーが出ました。
解決策を教えて頂きたくよろしくお願いいたします。
image

Hi @miwa_yamamoto,

It seems like the error happens because you are using DataRow instead of DataTable.

Are you using REFramework? If you are passing TransactionItem as DataRow into the formula, it won’t work.

Regards,
Kah Liang

1 Like

こんにちは。

変数Monthの後に、orかOrElseで繋げて、r(“計上月度”).toString=別の変数を入れてみてください。

1 Like

こんにちは

エラーの直接の原因は、Where区でフィルターした結果、該当する行が0件のためです。
UiPathの比較演算子ではワイルドカードは使えませんので、上記の式は不適切と思います。
例えば

DT=DT.AsEnumerable.Where(Function(r) System.Text.RegularExpressions.Regex.Match(row("計上月度").ToString(),"\d+").Value=m).CopyToDataTable

とすべきかと思います。(mは月を表す数字の文字列)

もしフィルターした結果が0件になる恐れがある場合は、一旦DataRowの配列にしておいて
その数でチェックする必要があるかと思います。

1 Like

ありがとうございます。
下記の件も、大変勉強になりました。

内容が難しくなってきていたので、
別のトピックでYoichi様に教えて頂いた置換を使い、
Kah_Liang様のこちらの式で作ってみようと思います。
今回、Yoichi様に教えて頂いた式はこれから応用が利く式なので
今後大切に使わせて頂きます。
本当にありがとうございます。

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.