I have been struggling with this all day. I have an Infopath form that is connected to two Sharepoint Lists.
SP List 1 (Project Charters):
Charter Title
Charter Opportunity
Charter Start Date
SP List 2 (Project Weekly):
Weekly Title
Weekly Opportunity.
I am attempting to combine these two lists into 1 repeating table on a new form. The Weekly Title field holds the same values as the Charter Title field, so I can match using Titles. I have found some resources, with this being the best:
http://www.infopathdev.com/forums/t/21262.aspx?PageIndex=2
There is a sample toward the end that does exactly what I want, but it will not work with my setup. Here is what I get:
As you can see in the picture, the "From my weeklys" column is always the same, and this is the problem. It should match with the corresponding field highlighted in red two the left. This is the formula in the calculated field:
Weekly_x0020_Opportunity[Weekly_x0020_Title = current()/Charter_x0020_Title]
The logic is to return the Weekly Opportunity description, where the Weekly Title matches the Charter Title; however, it only ever returns the same description. The testing column was used to prove that current()/Charter_x0020_Title was producing the unique titles for that row.
I feel like I am really close. The 3rd charter is missing a description, because my Weekly does not have a 3rd charter, so this is working properly. I just need to figure out how to bring-in the proper description.
Note: I am hoping for an Out-of-the-Box solution without coding.
FULL xPATH
xdXDocument:GetDOM("Project Weekly")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Weekly_x0020_Opportunity[xdXDocument:GetDOM("Project Weekly")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Weekly_x0020_Title = current()/d:Charter_x0020_Title]
The problem is that the path inside your predicate (between the []s) is using an absolute path rather than a relative one. You need to use a relative path.
This path (what you have now):
xdXDocument:GetDOM("Project Weekly")
/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Weekly_x0020_Opportunity
[xdXDocument:GetDOM("Project Weekly")/dfs:myFields/dfs:dataFields
/d:SharePointListItem_RW/d:Weekly_x0020_Title = current()/d:Charter_x0020_Title]
means "Get the first1 Weekly Opportunity field where any Weekly Title field in the Project Weekly data source has the value of the current Charter Title."
Or in other words, get the first Weekly Opportunity field in the Project Weekly data source any time the stuff between the square brackets is true.
This path:
xdXDocument:GetDOM("Project Weekly")
/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW
[d:Weekly_x0020_Title = current()/d:Charter_x0020_Title]/d:Weekly_x0020_Opportunity
means "Find the first1 SharePointListItem_RW where its Weekly Title is equal to the current Charter Title, and then get its Weekly Opportunity field."
So that's what you should use.
1 I am oversimplifying a bit here by saying "first". That path selects all of the nodes where that path is applicable, and then when InfoPath evaluates it, it takes the first result.
Related
It's a little complicated - but necessary - to explain the backstory, so some patience is requested.
I'm trying to parse an SEC Edgar filing (this Form 10-K, as a random example), not for its financial data, but for the list of Exhibits contained in a table toward the end of the document. Each document has in that table 3 attributes I'm interested in (exhibit number, title and URL), but for this example I'll focus only on the URL.
Finding all the URLs in the document is easy enough to begin with:
from lxml import etree
import lxml.html
for element in tree.iter('a'):
target = element.values()[0]
But since the document may contain hundreds of URLs, most of which are irrelevant, I have to filter the results for the presence of the word Archives which appears without exception in all Edgar URLs. So in the next stage, I get the xpath of each of them:
if target is not None and 'Archives' in target:
print(tree.getpath(element))
So far so good, but this is where I get stuck: it turns out that, for some really bizarre reason, each of the relevant URLs appears not in one but two (and in some documents - up to four!) tables and that these tables are not, unfortunately, the first or last tables in the document but randomly stuck somewhere in the middle. So, for example, Exhibit 10-5's xpaths are:
/html/body/document/type/sequence/filename/text/div[2]/table[9]/tr[17]/td[3]/p/a
/html/body/document/type/sequence/filename/text/div[2]/table[12]/tr[17]/td[3]/p/a
So the URL appears in exactly the same location in both table 9 and table 12. Obviously, I don't want this URL to appear twice is my final URL list, so in my final search I would like to run
for i in tree.xpath('//table[XXX]//*/a'):
print(i.values()[0])
Where XXX is either 9 or 12, in this example.
So back to the title of the question - how do I extract the index number of the table so I can select the higher (or lower) index number for my tree.xpath() expression? Altenatively, is there a way to stop the getpath search at table 9?
Given a list of items which have a date as one field, how can I separate one set which have a date in the first few days of the month from those which have a date in the last few days?
The items are gas bills, generally one per month, in a bank statement which relate to each of two separate buildings and need to go into two separate accounts. They were imported from a CSV file.
In practice, the number of lines involved is small, so I've just done it by hand, but the question of how to do it by formula and sort occurred to me, and I neither have nor found an answer.
I hope it is a slightly interesting question.
The function is simply called DAY. You can find it by clicking on the Function Wizard toolbar icon and looking under the Date&Time category.
For example, in cell B1 enter a formula like =DAY(A1) and fill down. Then go to Data -> Sort.
I've looked at many threads regarding COUNT and COUNTA, but I can't seem to figure out how to use it correctly.
I am new to DAX and am learning my way around. I have attempted to look this up and have gotten a little ways to where I need to be but not exactly. I think I am confused about how to apply a filter.
Here's the situation:
Four separate queries used to generate the data in the report; but only need to use two for the DAX function (Products and Display).
I have three columns I need to filter by, as follows:
Customer (Display or Products query; can do either)
Brand (Products query)
Location (Display query)
I want to count the columns based on if the data is unique.
Here's an example:
Customer: Big Box Buy;
Item: Lego Big Blocks;
Brand: Lego;
Location: Toys;
BREAK
Customer: Big Box Buy;
Item: Lego Star Wars;
Brand: Lego;
Location: Toys;
BREAK
Customer: Big Box Buy;
Item: Surface Pro;
Brand: Microsoft;
Location: Electronics;
BREAK
Customer: Little Shop on the Corner;
Item: Red Bicycle;
Brand: Trek;
Location: Racks;
In this example, no matter the fact that the items are different, we want to look at just the customer, the brand, and the location. We see in the first two records, the customer is "Big Box Buy" and the brand is "Lego" and the location is "Toys". This appears twice, but I want to count it distinct as "1". The next "Big Box Buy" store has the brand "Microsoft" and the location is "Electronics". It appears once and only once, and thus the distinct count is "1" anyway. This means that there are two separate entries for "Big Box Buy", both with a count of 1. And lastly there is "Little Shop on the Corner" which appears just once and is counted just once.
The "skeleton" of the code I have is basically just to see if I can get a count to work at all, which I can. It's the FILTER that I think is the problem (not used in the below example) judging by other threads I've read.
TotalDisplays = CALCULATE(COUNTA(products[Brand]))
Obviously I can't just count the amount of times a brand appears as that would give me duplicates. I need it unique based on if the following conditions are met:
Customer must be the same
Brand must be the same
Location must be the same
If so, we distinctly count it as one.
I know I ranted a bit and may seem to have gone in circles, but I was trying to figure out how to explain it. Please let me know if I need to edit this post or post clarification.
Many thanks in advance as I go through my journey with DAX!
I believe I have the answer. I used a NATURALINNERJOIN in DAX to create a new, merged table since I needed to reference all values in the same query (couldn't figure out how to do it otherwise). I also created an "unique identity" calculated column that combined data from multiple rows, but was hidden behind the scenes (not actually displayed on the report) so I could then take a measure of the unique values that way.
TotalDisplays = COUNTROWS(DISTINCT('GD-DP-Merge'[DisplayCountCalcCol]))
My calculated column is as follows:
DisplayCountCalcCol = 'GD-DP-Merge'[CustID] & 'GD-DP-Merge'[Brand] & 'GD-DP-Merge'[Location] & 'GD-DP-Merge'[Order#]
So the measure TotalDisplays now reports back the distinct count of rows based on the unique value of the customer ID, the brand, and the location of the item. I also threw in an order number just in case.
Thanks!
I am semi new to DAX and was struggling with Count and CountA formula, you post has helped me with answers. I would like to add the solution which i got for my query: Wanted count for Right Time start Achieved hence if anyone is looking for this kind of answer use below, filter will be selecting the table and adding string which you want to
RTSA:=calculate(COUNTA([RTS]),VEO_Daily_Services[RTS]="RTSA")
I have an issue with an excel spreadsheet I want to see if I can do without VBA just because it seems easier to implement that way. Basically, there are many columns in the sheet I want to sort. However, I merely want to look at three columns: the title column, the data column and the status column.
In a new spreadsheet, there will be four sections. Each section corresponds to 3 months of the year (ie Jan, Feb, Mar. will map to the first column on the new spreadsheet, April, May, June will map to the second column on the new spreadsheet).
Based on the date, and if the status column has the word "Finished" (in the original spreadsheet), I want to map the title to a certain column under the new spreadsheet based on the date criteria as described in the previous paragraph. So for example, if the original spreadsheet has following:
Title Date Status
Doc1 1/12/13 Finished
Doc2 2/10/13 UnFinished
Doc3 4/1/13 Finished
Doc4 3/31/13 Finished
Would map to, on the new spreadsheet:
1st Column | 2nd Column
Doc1 Doc3
Doc4
I have looked a lot into pivot tables but I can't "automate it" as much as I want to. I have gotten it down to the point where I can change the pivot tables into filtering based on date, but I want it even more automated than that. I've also tried excel formulas but that has been to no avail. Thanks for the help, I really appreciate it!
With a PivotTable it seems fairly easy to 'automate' as far as Sheet 2 as below:
but from there to the result requested is relatively 'manual' without VBA, so may not suit.
For my convenience I have changed the date formats. The PivotTable is constructed as usual/indicated without showing grand totals for rows or for columns (PivotTable Options, Totals & Filters). The Column Labels are Date with Grouping By Quarters with appropriate Starting at: and Ending at: (Group) and Collapse Entire Field (Expand/Collapse).
The formula in I6 is to convert the document count (always 1) to document name:
=IF(F6=1,$E6,"")
However, to allow room for additional quarters in the PivotTable the formula should be moved to the right. The formula would need to be copied across and down as necessary.
The process becomes more ‘manual’ with copying the results of these formulae, pasting them (with Special / Values) into a new location (in the example 2!A1) and, if required, deleting blanks.
This may be against the rules with regards to maintaining the integrity of the OP's request, but hopefully it doesn't offend :)
Here's another option.
Add another column (shame on me, I know) to the original data, and
called this Quarter. The formula that goes next to the existing data
is the following.
=IF(C2="Finished",IF(MONTH(B2)<=3,"Q1",IF(MONTH(B2)<=6,
"Q2",IF(MONTH(B2)<=9,"Q3","Q4"))),C2)
Basically, if the status is "Finished", then determine in what quarter the date is.
Create the pivot table with that data, and then add "Quarter" and
"Title" to the Row Labels (in that order)
Last thing would be to click the arrow next to "Row Labels" and select "Does not Equal" under "Label Filters". There you'll type "Unfinished" (no quotation marks). This will give you something like the image below.
From here the only manual thing you'll need to do is update the data range for the pivot table if more rows are added to the pivot table data and refresh the pivot table if the original data changes
NOTE: To address your question about sorting; after you do the steps above, you can select the Row Labels again and do an A>Z sort to get each quarter to be sorted in alphabetical order
i'm writing a program at work for a categorizing issue.
i get data in the form of CODE, DESCRIPTION, SUB-TOTAL for example:
LIQ013 COGNAC 25
LIQ023 VODKA 21
FD0001 PRETZELS 10
PP0502 NAPKINS 5
Now it all generally follows something like this...the problem is my company supplies numerous different bars. So there are like 800 records a month with data like this. My boss wants to breakdown the data so she knows how much we spend on a certain category each month. For example:
ALCOHOL 46
FOOD 10
PAPER 5
What I've thought of is I setup a sort of "data-base" which is really a csv text file that contains entries like this:
LIQ,COGNAC,ALCOHOL
LIQ,VODKA,ALCOHOL
FD,PRETZELS,FOOD
FD,POPCORN,FOOD
I've already written code that imports the database as a worksheet and separates each field into its own column. I want excel to look through the file and when it sees LIQ and COGNAC to assign it the ALCOHOL designator. That way I can use a pivot table to get the category sums. For example I want the final product to look like this:
LIQ013 COGNAC 25 ALCOHOL
LIQ023 VODKA 21 ALCOHOL
FD0001 PRETZELS 10 FOOD
PP0502 NAPKINS 5 PAPER
Does anyone have any suggestions? My worry is that a single point expression match to JUST the code i.e. just to LIQ without a match to COGNAC as well would maybe result in problems later when there are conflicting descriptions? I'd also like the user to be able to add ledger entries so that the database of recognized terms grows and becomes more expansive and hopefully more accurate.
EDIT
as per #Marc 's request i'm including my solution:
code file
please note that this is a pretty dumb-ed down solution. i removed a bunch of the fail-safes and other bits of code that were relevant to a robust code but not to our particular solution.
in order to get this to work there are two parts:
the first is the macro source code
the second is the actual file
because all the fail-safes are removed, the file needs to be imported to excel exactly the way it appears. i.e. Sheet1 on the googleDoc should be Sheet1 on the excel, start pasting data at cell "A1". before the macro is run, be sure to select cell "A1" in Sheet1. as i said, there are implementations in the finished product to make it more user friendly! enjoy!
EDIT2
These links suck. They don't paste well into excel.
If your comfortable with it I can email you the actual workbook. Which would help in preserving the formatting etc.
Use a lookup table in a separate sheet. Column A of the lookup sheet contains the lookup value (e.g. PRETZELS), Column B contains the category (FOOD, ALCOHOL, etc). In the cells where you want the category to show up in your original sheet (let's use D3 for the result where B3 holds the "PRETZELS" value), type this formula:
=VLOOKUP(B3,OtherSheet!$A$1:$B$500,2,FALSE)
That assumes that your lookup table is in range A1:B500 of a worksheet named "OtherSheet".
This formula tells Excel to find the lookup value (B3) in column A of your lookup and return the corresponding value from column B of your lookup table. Absolute references (the $) ensure that your formula won't increment cell references when you copy/paste the formula in other cells.
When you get new categories and/or inventory, you can update your lookup table in this one place by just adding new rows to it.