PowerApps-基于SQL查找数据,将集合分为较小的集合

发布于 2025-02-05 14:36:29 字数 5816 浏览 3 评论 0原文

- = - = - = - = -

编辑#3

好吧,这只是令人困惑的。

我将其范围缩小到一行...

我的代码示例,其中三个示例:

            ForAll(ScanDataCollection_SmartComm_MasterList,
              If(
//    line 1      (LookUp(Master_Transaction_Log, Result in Scan_Code).Scan_Code) in Result,
//    line 2      (LookUp(Master_Transaction_Log, "Comms Lockoff" in Transaction_Type).Scan_Code) in Result,
//    line 3      (LookUp(Master_Transaction_Log, "Comms Lockoff" in Transaction_Type And Result in Scan_Code).Scan_Code) in Result,
              Collect(SC_OnCommsHold,ThisRecord),
              Collect(SC_Remainder_1,ThisRecord));
            );

我的数据库具有符合上述条件的一个单个条目。

当我仅删除第1行时,例程运行良好。 SC_ONCOMMSHOLD会收到一个记录,而SC_Remainder_1获得了其他三个记录。

当我仅删除第2行时,例程运行良好。 SC_ONCOMMSHOLD会收到一个记录,而SC_Remainder_1获得了其他三个记录。

当我仅删除第3行时,结果就会失败。 SC_ONCOMMSHOLD没有收到任何记录。 在我看来,所有记录都堆积在sc_remainder_1中,

就像是 get 是第3行中的某种逻辑错误,但我绝对令人困惑。

- = - = - = - = - = -

编辑#2

以下序列产生我要寻找的结果:

            ClearCollect(SC_OnCommsHold, ScanDataCollection_SmartComm_MasterList);
            ClearCollect(SC_Remainder_1, ScanDataCollection_SmartComm_MasterList);
            Clear(SC_OnCommsHold);
            Clear(SC_Remainder_1);
            ForAll(ScanDataCollection_SmartComm_MasterList,
              If(
                (LookUp(Master_Transaction_Log, Result in Scan_Code, Scan_Code)) in Result,
              Collect(SC_OnCommsHold,ThisRecord),
              Collect(SC_Remainder_1,ThisRecord));
            );

但是以下序列失败了(为sc_oncommshold生成一个空的集合):

            ClearCollect(SC_OnCommsHold, ScanDataCollection_SmartComm_MasterList);
            ClearCollect(SC_Remainder_1, ScanDataCollection_SmartComm_MasterList);
            Clear(SC_OnCommsHold);
            Clear(SC_Remainder_1);
            ForAll(ScanDataCollection_SmartComm_MasterList,
              If(
                (LookUp(Master_Transaction_Log, Result in Scan_Code && "Comms Lockoff" in Transaction_Type, Scan_Code)) in Result,
              Collect(SC_OnCommsHold,ThisRecord),
              Collect(SC_Remainder_1,ThisRecord));
            );

我已经确认实际上有数据输入在适合该条件的Master_transaction_log中。

我认为我的查找线需要更好,但这是我想象的尽可能简单的,而且仍然无法正常工作。 argh。

- = - = - = - = -

为清晰#1编辑(我希望!):

master_transactions_log 数据库远超过半百万个条目,但我的扫描通常不到一百个。

我的四个测试条目(已保存到 scandatacollection_smartcomm_masterlist )是:

REQ2069120.RITM2374312.01 
REQ2075966.RITM2382958.01 
REQ2081369.RITM2389938.01 
REQ2091095.RITM2402123.01

我已经手动将记录添加到SQL数据库中(用于测试目的,而iem now 此刻只有一个与此条件匹配的单个条目)使得有a 单记录其中scan_code =“ req2081369.RITM2389938.01”和TransAction_Type =“新设备交付-comms comms lockoff”目前)

结果应该是两个集合:

sc_oncommshold ,其列为“ result_onhold”的列,该列仅包含一个条目:

REQ2081369.RITM2389938.01

sc_remainder_1 带有一个称为“结果”的列,来自ScandAtacollection_smartcomm_masterlist 减去条目的条目,现在已在SC_ONCOMMSHOLD 中:

REQ2069120.RITM2374312.01 
REQ2075966.RITM2382958.01 
REQ2091095.RITM2402123.01

我的代码是:

ClearCollect(SC_OnCommsHold, RenameColumns(ScanDataCollection_SmartComm_MasterList,"Result","Result_OnHold"));
ClearCollect(SC_Remainder_1, ScanDataCollection_SmartComm_MasterList);
//RemoveIf(SC_OnCommsHold, "REQ2081369.RITM2389938.01" in Result_OnHold);
RemoveIf(SC_OnCommsHold, IsEmpty(Filter(Master_Transaction_Log, Scan_Code = Result_OnHold, Transaction_Type="New Equipment Delivery - Comms Lockoff")));

运行几秒钟,所以我怀疑它实际上是通过数据库查看的,但是结果是结果是 sc_oncommshold 最终都获得了所有四个测试代码,这是其余所有内容的启动者。上面我的小评论线(#3)是我的帮助,以确保我在数据结构上进行思考,但是上面的实际实现(第4行)失败了。

我一直认为这条线是踢我的一条线,但我无法弄清楚我需要什么。

在得到 SC_ONCOMMSHOLD 正确填充后,我希望能够使用相同的技巧来 de sc_remainder_1 中填充这些元素。

- = - = - = - = -

真正在此方面挣扎...

我从集合开始: scandatacollection_smartcomm_masterlist

它看起来像这样:

Result
REQ1991799.RITM2280596.01 
REQ2048874.RITM2349401.01 
REQ2037354.RITM2335400.01 

我有一个数据库表: master_transaction_log

...具有三个特定兴趣的列:

Timestamp
Scan_Code
Transaction_Type

我想以两个 collections:

SC_ReturnToDepot
Result
REQ1991799.RITM2280596.01 

SC_Remainder_1
Result
REQ2048874.RITM2349401.01 
REQ2037354.RITM2335400.01 

标准如下:对于任何给定的结果, in scandatacollection_smartcomm_masterlist ,如果:

数据库记录具有scan_code =结果 transaction_type =“新设备交付 - CUST。MSG:设备返回depot” and and and and and timestamp> 72小时前,然后将结果值添加到 sc_returntodepot

sc_remainder_1 均为所有剩余值不符合上述标准。

到目前为止,我到目前为止都在杀死我:

            ClearCollect(SC_ReturnToDepot,
              ForAll(ScanDataCollection_SmartComm_MasterList,
                ...?
              );
            );

            ClearCollect(SC_Remainder_1,
              ForAll(ScanDataCollection_SmartComm_MasterList,
                ...?
              );
            );

我有一种感觉,我是否可以钉住一条一行代码,我参加了比赛,但这是只是...嗯,我的大脑在混蛋。

- = - = - = - = - = -

澄清,

  • 这是一个以许多步骤级联过程开头的一部分 scandatacollection_smartcomm_masterlist
  • 我无法更改SQL表上的数据,也无法切换 我所有的逻辑结构都可以在存储过程中完成所有操作, 等等。
  • 如果有一种方法可以发送特定的SQL查询, 则 并且该特定的SQL查询将产生正确的结果 收集,然后我对此开放,但是结果必须是 如上所述,集合,因为我将这些结果收集到 喂食其他过程。

-=-=-=-=-

Edit #3

Okay, this is just baffling as heck.

I've narrowed this down to one single line...

A sample of my code, with three examples:

            ForAll(ScanDataCollection_SmartComm_MasterList,
              If(
//    line 1      (LookUp(Master_Transaction_Log, Result in Scan_Code).Scan_Code) in Result,
//    line 2      (LookUp(Master_Transaction_Log, "Comms Lockoff" in Transaction_Type).Scan_Code) in Result,
//    line 3      (LookUp(Master_Transaction_Log, "Comms Lockoff" in Transaction_Type And Result in Scan_Code).Scan_Code) in Result,
              Collect(SC_OnCommsHold,ThisRecord),
              Collect(SC_Remainder_1,ThisRecord));
            );

My database has one single entry that fits the above criteria.

When I uncomment only line 1, the routine runs great. SC_OnCommsHold receives one record, and SC_Remainder_1 gets the other three.

When I uncomment only line 2, the routine runs great. SC_OnCommsHold receives one record, and SC_Remainder_1 gets the other three.

When I uncomment only line 3, the result fails. SC_OnCommsHold receives no records. All records get piled into SC_Remainder_1

It seems to me like it's got to be some sort of logical error in line 3, but I an absolutely baffled.

-=-=-=-=-

Edit #2

The following sequence produces the result I'm looking for:

            ClearCollect(SC_OnCommsHold, ScanDataCollection_SmartComm_MasterList);
            ClearCollect(SC_Remainder_1, ScanDataCollection_SmartComm_MasterList);
            Clear(SC_OnCommsHold);
            Clear(SC_Remainder_1);
            ForAll(ScanDataCollection_SmartComm_MasterList,
              If(
                (LookUp(Master_Transaction_Log, Result in Scan_Code, Scan_Code)) in Result,
              Collect(SC_OnCommsHold,ThisRecord),
              Collect(SC_Remainder_1,ThisRecord));
            );

but the following sequence fails out (produces an empty Collection for SC_OnCommsHold):

            ClearCollect(SC_OnCommsHold, ScanDataCollection_SmartComm_MasterList);
            ClearCollect(SC_Remainder_1, ScanDataCollection_SmartComm_MasterList);
            Clear(SC_OnCommsHold);
            Clear(SC_Remainder_1);
            ForAll(ScanDataCollection_SmartComm_MasterList,
              If(
                (LookUp(Master_Transaction_Log, Result in Scan_Code && "Comms Lockoff" in Transaction_Type, Scan_Code)) in Result,
              Collect(SC_OnCommsHold,ThisRecord),
              Collect(SC_Remainder_1,ThisRecord));
            );

I have confirmed that there is in fact a data entry in Master_Transaction_Log that fits that criteria.

I assume my LookUp line needs to be better, but this is about as simple as I can imagine and it's still not working. Argh.

-=-=-=-=-

Edited for clarity #1 (I hope!):

The Master_Transactions_Log database is well over half a million entries, but my scans are typically under a hundred in count.

My four test entries (saved into ScanDataCollection_SmartComm_MasterList) are:

REQ2069120.RITM2374312.01 
REQ2075966.RITM2382958.01 
REQ2081369.RITM2389938.01 
REQ2091095.RITM2402123.01

I have manually added a record into the SQL database (for testing purposes, and I know at this moment that there is only one single entry that matches this criteria) such that there is a single record where Scan_Code = "REQ2081369.RITM2389938.01" and Transaction_Type = "New Equipment Delivery - Comms Lockoff" (just trying to keep it simple right now)

The result should be two collections:

SC_OnCommsHold with a column called "Result_OnHold" which only contains a single entry:

REQ2081369.RITM2389938.01

SC_Remainder_1 with a column called "Result" which contains all entries from ScanDataCollection_SmartComm_MasterList minus entries that are now in SC_OnCommsHold:

REQ2069120.RITM2374312.01 
REQ2075966.RITM2382958.01 
REQ2091095.RITM2402123.01

My code at-the-moment is:

ClearCollect(SC_OnCommsHold, RenameColumns(ScanDataCollection_SmartComm_MasterList,"Result","Result_OnHold"));
ClearCollect(SC_Remainder_1, ScanDataCollection_SmartComm_MasterList);
//RemoveIf(SC_OnCommsHold, "REQ2081369.RITM2389938.01" in Result_OnHold);
RemoveIf(SC_OnCommsHold, IsEmpty(Filter(Master_Transaction_Log, Scan_Code = Result_OnHold, Transaction_Type="New Equipment Delivery - Comms Lockoff")));

It takes a few seconds to run, so I suspect it's actually looking through the database, but the result is that SC_OnCommsHold ends up with all four test codes, and that is a non-starter for the rest of everything. My little commented-out line (#3) above was my helper to make sure I was thinking right on the data structures, but the actual implementation above (line #4) fails.

I keep thinking that this line is the one kicking me, but I can't figure out what I need.

After I can get SC_OnCommsHold properly populated, I'm hoping to be able to use the same trick to depopulate those elements from SC_Remainder_1.

-=-=-=-=-

I'm really struggling with this...

I start with a collection: ScanDataCollection_SmartComm_MasterList

It looks like this:

Result
REQ1991799.RITM2280596.01 
REQ2048874.RITM2349401.01 
REQ2037354.RITM2335400.01 

I have a database table:
Master_Transaction_Log

...which has three particular columns of interest:

Timestamp
Scan_Code
Transaction_Type

I would like to end up with TWO collections:

SC_ReturnToDepot
Result
REQ1991799.RITM2280596.01 

SC_Remainder_1
Result
REQ2048874.RITM2349401.01 
REQ2037354.RITM2335400.01 

The criteria is as follows: for any given Result in ScanDataCollection_SmartComm_MasterList, if:

A database record has Scan_Code = Result AND Transaction_Type = "New Equipment Delivery - Cust. Msg: Equipment Returning to Depot" AND Timestamp > 72 hours ago, then that value of Result is added to SC_ReturnToDepot

SC_Remainder_1 are all remaining values that do not fit the above criteria.

I got as far as this so far, but it's killin' me after this:

            ClearCollect(SC_ReturnToDepot,
              ForAll(ScanDataCollection_SmartComm_MasterList,
                ...?
              );
            );

            ClearCollect(SC_Remainder_1,
              ForAll(ScanDataCollection_SmartComm_MasterList,
                ...?
              );
            );

I have a feeling if I can just nail that one single line of code, I am off to the races, but this is just... ugh, my brain is being a jerk.

-=-=-=-=-=-

Clarifications

  • This is part of a many-steps cascading process that starts with
    ScanDataCollection_SmartComm_MasterList
  • I am not in a position where I'm able to change the data on the SQL table, nor can I switch
    all my logic structure over to doing it all in Stored Procedures,
    etc.
  • If there was a way in PowerApps to send a specific SQL query,
    and that specific SQL query would produce the right results in a
    Collection, then I'm open to that, but the result has to be the
    Collection as described above, because I use these resultant Collections to
    feed other processes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

☆獨立☆ 2025-02-12 14:36:29

您可以通过几种方式处理这种情况。您可以使用两个过滤器表达式创建每个集合,其中第二个条件是第一个的否定条件,沿另一个选项的行为

ClearCollect(
  SC_ReturnToDepot,
  Filter(
    Master_Transaction_Log,
    Scan_Code in ScanDataCollection_SmartComm_MasterList,
      And Transaction_Type = "New Equipment Delivery - Cust. Msg: Equipment Returning to Depot"
      And Timestamp > DateAdd(Now(), -3, TimeUnit.Days)));
ClearCollect(
  SC_Remainder_1,
  Filter(
    Master_Transaction_Log,
    Not(
      Scan_Code in ScanDataCollection_SmartComm_MasterList,
        And Transaction_Type = "New Equipment Delivery - Cust. Msg: Equipment Returning to Depot"
        And Timestamp > DateAdd(Now(), -3, TimeUnit.Days))));

是使用forall表达式,对于每个记录,使用if表达式来插入两个集合之一,类似于以下公式:

Clear(SC_ReturnToDepot);
Clear(SC_Remainder_1);
ForAll(
  Master_Transaction_Log,
  If(
    Scan_Code in Master_Transaction_Log
      And Transaction_Type = "New Equipment Delivery - Cust. Msg: Equipment Returning to Depot"
      And Timestamp > DateAdd(Now(), -3, TimeUnit.Days),
    Collect(SC_ReturnToDepot, ThisRecord),
    Collect(SC_Remainder_1, ThisRecord)))

There are a couple of ways in which you can go about this scenario. You can create each collection with two Filter expressions, where the condition of the second one is the negation of the first, something along the lines of

ClearCollect(
  SC_ReturnToDepot,
  Filter(
    Master_Transaction_Log,
    Scan_Code in ScanDataCollection_SmartComm_MasterList,
      And Transaction_Type = "New Equipment Delivery - Cust. Msg: Equipment Returning to Depot"
      And Timestamp > DateAdd(Now(), -3, TimeUnit.Days)));
ClearCollect(
  SC_Remainder_1,
  Filter(
    Master_Transaction_Log,
    Not(
      Scan_Code in ScanDataCollection_SmartComm_MasterList,
        And Transaction_Type = "New Equipment Delivery - Cust. Msg: Equipment Returning to Depot"
        And Timestamp > DateAdd(Now(), -3, TimeUnit.Days))));

Another option would be to use a ForAll expression and for each record, use an If expression to insert into one of the two collections, similar to the formula below:

Clear(SC_ReturnToDepot);
Clear(SC_Remainder_1);
ForAll(
  Master_Transaction_Log,
  If(
    Scan_Code in Master_Transaction_Log
      And Transaction_Type = "New Equipment Delivery - Cust. Msg: Equipment Returning to Depot"
      And Timestamp > DateAdd(Now(), -3, TimeUnit.Days),
    Collect(SC_ReturnToDepot, ThisRecord),
    Collect(SC_Remainder_1, ThisRecord)))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文