Count Unique Values in Repeating Table - InfoPath Dev
in

InfoPath Dev

Count Unique Values in Repeating Table

Last post 06-23-2015 12:22 PM by SFC_Simon. 12 replies.
Page 1 of 1 (13 items)
Sort Posts: Previous Next
  • 06-22-2015 09:07 AM

    Count Unique Values in Repeating Table

    Hello all,

    I have been asked to develop an InfoPath Form that displays a report based on information that is housed in an Access Data Base. I have had our programmers create a WebService that allows me to query said Data Base with a Start and End Date. The WebService returns all of the information that falls within that date range.

    I have displayed the repeating table from the Data Connection on the Form and it is returning all of the information that falls within that date range when I set the dates and query the Data Connection.

    I now need to create a field which displays a Count for all of the participants who have performed a mission within that date range. However when a participant has completed multiple missions within that data range. I do not want to count them multiple times. I only want to count that particular Participant_Name once. Because this report only cares about how many different people were asked to participate in missions between that date range.

    So what I will need is to be told how to count only unique items within a repeating table from a Data Connection that I do not have the ability to create new fields within. I have tried: count(Participant_Name[preceding-sibling::* != Participant_Name]) but that does not return the correct count.

    I have spent several days with googe, try, fail and so am now onto the forums, lol. I would appreciate any advice.

    Thank you

    Good... Bad... Im the guy with the gun.
  • 06-22-2015 03:55 PM In reply to

    Re: Count Unique Values in Repeating Table

     What is the full XPath to Participant_Name? You can right click the node in the data source task pane and select copy XPath - I think I can help you with your formula.

    Hilary Stoupa

  • 06-23-2015 09:54 AM In reply to

    Re: Count Unique Values in Repeating Table

    XPath Participant Name:

    /dfs:myFields/dfs:dataFields/ns3:BuildReportResponse/ns3:BuildReportResult/ns3:Reports/ns3:CReportBuilder/ns3:Participations/ns3:CReportBuilderParticipation/ns3:Participant_Name

       

    Also here is the current formula that I am trying to use:

    count(xdXDocument:GetDOM("BuildReport")/dfs:myFields/dfs:dataFields/ns3:BuildReportResponse/ns3:BuildReportResult/ns3:Reports/ns3:CReportBuilder/ns3:Participations/ns3:CReportBuilderParticipation/ns3:Participant_Name[(../preceding-sibling::* != xdXDocument:GetDOM("BuildReport")/dfs:myFields/dfs:dataFields/ns3:BuildReportResponse/ns3:BuildReportResult/ns3:Reports/ns3:CReportBuilder/ns3:Participations/ns3:CReportBuilderParticipation/ns3:Participant_Name) and (. != "")])

    Thank you.

    Good... Bad... Im the guy with the gun.
  • 06-23-2015 10:22 AM In reply to

    Re: Count Unique Values in Repeating Table

     Maybe try this?

    count(xdXDocument:GetDOM("BuildReport")/dfs:myFields/dfs:dataFields/ns3:BuildReportResponse/ns3:BuildReportResult/ns3:Reports/ns3:CReportBuilder/ns3:Participations/ns3:CReportBuilderParticipation/ns3:Participant_Name[. != ../preceding-sibling::ns3:CReportBuilderParticipation/ns3:Participant_Name and . != ""]) 

    Hilary Stoupa

  • 06-23-2015 10:34 AM In reply to

    Re: Count Unique Values in Repeating Table

    Unfortunately that returns the same number as:

    count(xdXDocument:GetDOM("BuildReport")/dfs:myFields/dfs:dataFields/ns3:BuildReportResponse/ns3:BuildReportResult/ns3:Reports/ns3:CReportBuilder/ns3:Participations/ns3:CReportBuilderParticipation/ns3:Participant_Name[(../preceding-sibling::* != xdXDocument:GetDOM("BuildReport")/dfs:myFields/dfs:dataFields/ns3:BuildReportResponse/ns3:BuildReportResult/ns3:Reports/ns3:CReportBuilder/ns3:Participations/ns3:CReportBuilderParticipation/ns3:Participant_Name) and (. != "")])

    When you look it over out of XPath:

    count(Participant_Name[(preceding-sibling::* != Participant_Name) and (. != "")])
    or
    count(Participant_Name[. != preceding-sibling::CReportBuilderParticipation/Participant_Name and . != ""])

    They both seem to make sense.  It should be returning a count of values that are unique.

    If I run a report for 3 June.  The Table returns 6 names and none of the names are repeated.  However both my formula and the one you suggested returns a count of 3.  That's where I cant make sense of it.

    Good... Bad... Im the guy with the gun.
  • 06-23-2015 10:54 AM In reply to

    Re: Count Unique Values in Repeating Table

    Sorry, I think we need 'not' instead of '!='

     count(xdXDocument:GetDOM("BuildReport")/dfs:myFields/dfs:dataFields/ns3:BuildReportResponse/ns3:BuildReportResult/ns3:Reports/ns3:CReportBuilder/ns3:Participations/ns3:CReportBuilderParticipation/ns3:Participant_Name[not(. = ../preceding-sibling::ns3:CReportBuilderParticipation/ns3:Participant_Name) and . != ""])

    Hilary Stoupa

  • 06-23-2015 11:34 AM In reply to

    Re: Count Unique Values in Repeating Table

    Well that works differently for sure, but still not accurate.  That simply returns all names regardless of the preceding-siblings.

    Good... Bad... Im the guy with the gun.
  • 06-23-2015 11:36 AM In reply to

    Re: Count Unique Values in Repeating Table

    Questions on a side note:

    what does preceding-sibling::* mean vs the full path after :: ?

     what does current() mean and how exactly can that be used?

    Good... Bad... Im the guy with the gun.
  • 06-23-2015 11:45 AM In reply to

    Re: Count Unique Values in Repeating Table

     Here's a sample that shows this - download the linked file, right click the local copy, select design, preview, and change values, insert items, etc.

    Hilary Stoupa

  • 06-23-2015 11:57 AM In reply to

    Re: Count Unique Values in Repeating Table

     Well, actually my expression uses a relative path after the preceding-sibling::.

    http://www.w3schools.com/xpath/xpath_axes.asp

    http://stackoverflow.com/questions/12347412/concept-xml-xlst-preceding-sibling-and-ancestor 

    The * selects all elements. 

    Current is the current element. Generally useful when your current element is in a repeating structure - like you have conditional formatting hide a row when some other value is equal to the current row's ID....

    http://www.w3schools.com/xsl/func_current.asp

    http://stackoverflow.com/questions/1022345/current-node-vs-context-node-in-xslt-xpath 

    Hilary Stoupa

  • 06-23-2015 12:12 PM In reply to

    Re: Count Unique Values in Repeating Table

    I will read though those links to develop a better grasp on what I am doing.  There is only so much a person can learn from google, Ctrl+C, Ctrl+v, lol.  While I have learned a lot from that method, I have learned more though this single forum entry.

    I will also look over the template and attempt to repurpose what it contains.  I was just told I no longer need to track the names in a unique manner and so no longer need this soultion.  I litterally just got out of that meeting with the customer, lol.

    But I will certainly read, preview, test and make notes.

    The best part about your support is that I have already gotten so many of my answers by reading posts you replied in.  When I saw your face in the reply line to my post.  I thought to myself "Jack Pot" lol.
    I truly appreciate all of your support on this and on the many many many other posts I have read your replies on.

    Thank you

    Good... Bad... Im the guy with the gun.
  • 06-23-2015 12:16 PM In reply to

    Re: Count Unique Values in Repeating Table

     I'm happy this thread & the forum in general have been helpful to you - how funny that the requirements changed right when you were working out the solution - isn't that the way it always goes? :)

    Have a great day! 

    Hilary Stoupa

  • 06-23-2015 12:22 PM In reply to

    Re: Count Unique Values in Repeating Table

    Yeah, the requirements always change right before you get it.  But now i've got this problem on the brain and so won't stop till I've solved it.

    Then again, isn't that the way it always goes for us, lol.

    Thanks again

    Good... Bad... Im the guy with the gun.
Page 1 of 1 (13 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.