How do I use XL Data Tables with XLOOKUP for Data Validation - excel

I have a data table based on a query -> tblPrimaryProducts
tblPrimaryProducts has many columns, some of which are Category, SubCategory and Item.
If I were to use a filter on Category I would of course be able to see the SubCategories and Items in that Category. Likewise if I were to apply a filter to SubCategory in turn I would see a list of on the items in that specific Category + SubCategory selection. Ultimately this is the goal of data validation I am trying to implement.
There is a data entry table -> tblPackages
tblPackages has many fields, but importantly the three listed above need to be implemented in a controlled way via data validation so that each row can have the correctly selected Category + SubCategory + Item
I am unable to change the data table into an array or simple (or dynamic) named range because it will be refreshed any number of times and the column positions will potentially alter. This means that I have to use the table based naming system for both tables.
What I have so far is the following for a data validation formula using XLOOKUP:
XLOOKUP([#[Primary Category]] & [#[Primary SubCategory]], tblPrimaryProducts[Category] & tblPrimaryProducts[SubCategory], tblPrimaryProducts[Item],,0)
[#[Primary Category]] and [#[Primary SubCategory]] are fields in the tblPackages data entry table. The other fields listed come from tblPrimaryProducts. So far I have entered data by hand to test this out.
In the XL Formula window (where you can 'see' what your formula is doing while you fill in the fields) this seems to work and provides the output expected.
When I try to implement this as data validation it complains about an error in formula. If I place an INDIRECT at the beginning I get the syntax error popup. I have had issues in the past with INDIRECT that have been solved with the careful use of quotation marks. I cannot seem to find a way here to do this.
Does anyone have any ideas on how I might implement some data validation based off of a data table (as opposed to an array), or the query that the table is based on in this situation? Under normal circumstances I would use dynamic named ranges but here I cannot.
Any help or ideas greatly appreciated

In Office365 the following formula will get you the list of "Items" that satisfy the "Category" and "Subcategory" conditions.
=FILTER(tblPrimaryProducts[Item],(tblPrimaryProducts[Category]=[#[Primary Category]])*(tblPrimaryProducts[Subcategory]=[#[Primary Subcategory]]),"")
It will give you a #SPILL! error if inserted in a Table and it returns multiple items that match the two criteria. You may have to redesign your output table.
If you are intending to display just the filtered values, you can then use two dropdowns with list of categories and subcategories. The filter function can then use these cells to filter the Items from source data and display as a list below.

Related

Incorrect data being pulled from a SharePoint list to Power BI

When I pull data from a SharePoint list into Power BI, the values are pulled incorrectly for columns having the data type -
Person or Group - instead of names, numerical values are pulled. I guess these are the IDs of the values
Lookup - instead of the actual values, '[list]' is pulled in a nested column. When I expand, numerical values are shown. Again, seems like IDs
All other data types are pulled properly.
To work around this problem, I first pull the data from the list to Excel and then to PBI. However, I want to eliminate this manual step as the list will have frequent updates and I will need to pull the list data into Power BI regularly.
What should be done to pull the actual values as they appear in the list?
For the lookup columns: You need to pull in the lists where the lookup values are being looked up from and then create a relationship based on ID.
For the People: Look here:fully explained how to deal with Person object
I did some looking around and was able to find a solution.
Using the FieldValuesAsText column in the Query Editor, I got the values in the table. values for both column types were available. Since, I only needed the text values it solved the purpose.

How to identify notesView columns that have column totals defined for them?

I have several views that have 'column totals' defined in some columns of these views. The totals can be in different positions in each view. I'm looking a for a fast, reliable way of identifying which columns have totals before I scan these columns and views.
Ideally, I want a 'isTotal' property on the column defintion (NotesViewColumn), but that property is not defined/available.
I can see that totals in the ColumnValues array does return a 'double' datatype where a column exists, but I can only see this once I've started scanning the data in the view, and I want this detail before I start looking at the data. (For information, the ColumnValues for a category notesViewEntry is an array containing: strings for cat columns, 'empty' for untotalled fields, and doubles for totals).
I can (of course) hard-code this detail somewhere, but it seems archaic to have to do this. I can 'getFirstDoc' to work out the ColumnValues in a 'pre-loop' check, but this seems 'wasteful'.
PS: I have seen something called 'ColumnValuesIndex' but this appears to be an undocumented feature which I would prefer not to use. However, if there were an 'isTotal' undocumented feature - I'd be ok with it!
The only solution I can think of to do this before you scan the data is to export the view design to DXL, then check the DXL for attributes or elements that specify whether each column shows totals.
I'm assuming view columns in DXL have an attribute or child element for this purpose. I haven't checked.
In case you've never done anything like this, using a NotesDXLExporter with either a NotesDOMParser or a NotesSAXParser, you can export selected design elements to in-memory DXL and programmatically analyse it.
As outlined in the original post, looking at the ColumnValues of a NotesViewEntry (NVE) on a category row does provide an array of values you can use to determine if any specific column is either a category string, empty, or a total. The totals have a datatype of double so stepping over the columns in a loop can easily flag the totals.
If the view has categories, then the first NVE in the view will give these details. A simple 'NotesView.GetFirstEntry().ColumnValues' will return the array. If the view has totals, but not categories, you can 'GetLastEntry' for the totals row at the bottom of the view.
Reading the totals is then just a case of looking for category rows (nve.IsCategory) and extracting the totals from the nve.ColumnValues.
Performance is reasonable and can be made a bit quicker by building a booleans array pre-loop of where the totals exist.

SSAS Calculated member that knows if the user is using the report filter

I am trying to write a calculated member which acts differently depending on whether the user is filtering by that member or has it dragged down as rows or columns on their pivot table (using Excel).
The rules are:
1. If the user is using the date dimensin as a Report Filter in Excel, then the calculated member should get the maximum date out of all dates that they are filtered by.
2. If they have the date dimension as rows on the pivot table, then I need to apply ClosingPeriod and some other logic.
Please try this. The idea came from here.
Basically the dynamic named set represents what's in the report filters. And the EXISTING keyword trims the list of days down to the filter context of the current cell letting you detect say if one month is on rows. Compare counts and you can detect what the user did.
CREATE HIDDEN DYNAMIC SET CURRENTCUBE.SelectedDays as
[Date].[Date].[Date].Members;
CREATE MEMBER CURRENTCUBE.[Measures].[My Calc] as
CASE
WHEN SelectedDays.Count > {existing [Date].[Date].[Date].Members}.Count
THEN Tail({existing [Date].[Date].[Date].Members},1).Item(0).Item(0).Name
WHEN SelectedDays.Count < [Date].[Date].[Date].Members.Count
THEN Tail(SelectedDays,1).Item(0).Item(0).Name
END
Performance is going to not be good. And I suspect users will be confused with the results of your calc. If you want to describe the business scenario more I can maybe recommend a better approach.

Dynamic validation list in Excel

I have an issue regarding data validation in Excel, namely how to dynamically set the validation source.
I have three tables, where the first contains a product ID and a product name. The second table contains a product ID together with a serial number. A third table has three columns; one for product ID, one for serial number and a description for e.g. error reporting.
What I want to do is related to the third column where I select the product ID in a drop-down box which is linked to the first table. This works perfectly fine. The second column though, must only allow serial numbers related to the product ID selected according to the relationship in the second table. Hence, the data validation list must be dynamically generated by the input in the first column.
The reason for having it in Excel is due corporate reasons and personally I'd use an SQL-database for this very issue. E.g. if I were to use SQL-syntax to generate the validation list, the corresponding SQL-statement would be:
SELECT serialNumber WHERE productId = 12345;
I've tried using the INDEX-MATCH, but unfortunately MATCH only returns a scalar value rather than an array. I have not come across array functions prior to today, but I assume such might be included in order to accomplish this and have tried a bit without success.
If I somehow were to acquire an array returning the row numbers where there is a match, the INDEX-function would accomplish my needs, I presume.
My question is therefore, is there a method to acquire an array of matched values or can my problem be solved using a more elegant solution? If it could be of value if it can be made without VBA, also for corporate security reasons.
Thanks in advance!

How do I SUMIF one PowerPivot table according to the rows of a second PowerPivot table?

I have two tables: one of customers ("Donor"), and one of transactions ("Trans"). In Donor, I want a "Total" column that sums all the transactions by a particular Donor ID, which I would calculate in a standard Excel table thus:
=SUMIF(Trans[Donor ID],[#ID],Trans[Amt])
Simple! How do I do the same thing with a DAX formula? I thought
=CALCULATE(SUM(Trans[Amt]),Trans[Donor ID]=[ID])
would do it, but I get the error
Column "ID" cannot be found or may not be used in this expression.
Strangely, when I use
=CALCULATE(SUM(Trans[Amt]),Trans[Donor ID]=3893)
I do get the total for ID 3893.
Eschewing CALCULATE, I did find that this works:
=SUMX(FILTER(Trans, Trans[Donor ID]=[ID]),[Amt])
...but it only allows the one filter, and I'll need to be able to add more filters, but:
=SUMX(CALCULATETABLE(Trans, Trans[Donor ID]=[ID]),[Amt])
...(which I understand is like FILTER but allows for multiples) does not work.
Can you identify what I'm doing wrong?
After putting together a quick model that looks like this:
I've confirmed that this DAX forumla works as a Calculated Column in the Donor table:
=CALCULATE(SUM(Trans[Amt]), FILTER(Trans, Trans[Donor] = Donor[DonorKey]))
The key here is to make sure that the relationship between the two tables is correctly configured, and then make sure to use the combination of CALCULATE() and FILTER() -- filtering the trans table based on the current donor context.

Resources