Referencing a dynamic name in PowerQuery results in an error - excel

I have created a new name (variable) in excel using the Name Manager which is called fPath. The value for the name is =CELL("filename").
I would like to reference this name as a parameter to the source within a function query. But, when I try to invoke the function within the Power Query Editor, I get an error that it wasn't able to find the name.
When the name refers to a cell within the sheet, this works perfectly but when a name is created without a reference to a cell, it is unable to find it.
Am I correct in assuming that what I'm trying to do is not possible?
EDIT:
Here's the code for for the Function Query where I have defined a parameter which is then used to dynamically get the source of the file.
[]

Please see this from Ken Puls
https://www.excelguru.ca/blog/2014/11/26/building-a-parameter-table-for-power-query/

Try this:
= Excel.CurrentWorkbook(){[Name="fPath"]}[Content]
Or:
= Excel.Workbook(File.Contents("C:\YourFile.xlsx"), null, true){[Item="fPath",Kind="DefinedName"]}[Data]

Related

Azure Data Factory concating syntax

I'm trying to run a pipeline that results a select with where be the system triggername system output.
I've tried to use :
#concat(concat(concat(concat('select * from ',item().DB_CARGA,'.',item().SC_CARGA,'.',item().tb_carga, 'where ' ,item().DS_CARGA ,'=', string(pipeline().TriggerName)))))
But I'm getting the following error:
Could anyone help me with the right syntax?
I reproduced this and got similar error when I used your syntax.
In your dynamic expression, there should be a space between table name and where and also trigger name should be enclosed in single quotes.
Please go through the below procedure to resolve the error.
First, I have a lookup activity which will give database name, table name and SQL table column(trigger column name). Give this to Foreach.
I have created sample tables with trigger_column column and gave some values.
In pipeline I have created trigger with same name mytrigger. Inside Foreach for my demo I have used lookup query. You can use your activity as per the requirement.
Dynamic content:
You can do this with single concat function.
#concat('select * from ',item().database,'.',item().table_name, ' where ' ,item().trigger_name ,'=','''',string(pipeline().TriggerName),'''')
This will give the SQL query like this when Executed.
Output when triggered:

Office Script Excel Pivot Table Count Instead of Sum

I'm using Office Script to generate a pivot table and that works. However, for my data hierarchy, I need "count" instead of the default "sum". How do I go about doing that?
I'm adding a hierarchy using the following - this works but summarizes by "sum"
pivotTable.addRowHierarchy(pivotTable.getHierarchy("Company"));
pivotTable.addDataHierarchy(pivotTable.getHierarchy("Unit ID"));
From the script reference page, I need to somehow embed the count function into the above snippet. Does anyone know how to do that? I tried "Record Actions", but it wasn't able to catch the switch from "sum" to "count".
Thanks a lot
Figured it out - to change the summarize function, we need to chain the aggregate function to the end of addDataHierarchy.
The second line in the previous example therefore becomes:
pivotTable.addDataHierarchy(pivotTable.getHierarchy("Unit ID")).setSummarizeBy(ExcelScript.AggregationFunction.count);
For more details refer to setSummarizeBy(summarizeBy).

Getting access to a sheets Title block using python

Dynamo Script
Within Dynamo I was able to adjust the title block per sheet but I was requested to simplify it into a button click using python only.
I can find the sheets but I can not adjust the parameters per sheet. I believe this is because the parameter I am trying to toggle on and off is located within the Titleblock and not on the sheet it self. I thought maybe I would need to unwrap these but I could not get the function to work outside of Dynamo. Any help would be appreciated.
sheet_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Sheets) \
.WhereElementIsNotElementType() \
.ToElements()
for sheet in sheet_collector:
print(sheet.Name)
The snippet above is how I am sourcing all the sheets and I have been able to find everyone but when searching for the custome parameter, it comes up nil.
To get the FamilyInstance of the title block you can use this:
var titleBlockFamInst = new FilteredElementCollector(doc, viewSheetId).OfCategory(BuiltInCategory.OST_TitleBlocks).FirstElement() as FamilyInstance;

Data Parameter in Excel not working with Access Query Connection

I have a connection to an Access DB query within Excel. The field in the Access query is an expression turning a field into a proper date. The problem that I'm having in Excel lies within passing the parameter from a cell containing the date that I want the query to run for. The results are either completely wrong or result in nothing. I have tried modifying the parameter cell to just about everything to no avail. I have tried the edit query option under view connection and when prompted to put in the value for the parameter, it actually returns the data I want. I would thing that this would be exactly the same parameter it would be grabbing from the formatted cell?
I have attached my connection's SQL command text below. And also an image with more detail and screenshots.
This is the command text from Excel containing my Where clause:
SELECT Query1.SETYPE, Query1.`SEORD#`, Query1.ORBILL, Query1.ORCUST, Query1.ORLDAT,
Query1.ORCONS, Query1.SESEV, Query1.CMTYPE, Query1.CMTEXT, Query1.ORDDATfix
FROM `C:\USERS\DRED\DESKTOP\ServiceFailures.accdb`.Query1 Query1
WHERE Query1.ORDDATfix =?
SELECT Query1.SETYPE, Query1.`SEORD#`, Query1.ORBILL, Query1.ORCUST, Query1.ORLDAT, Query1.ORCONS, Query1.SESEV, Query1.CMTYPE, Query1.CMTEXT, Query1.ORDDATfix
FROM `C:\USERS\DRED\DESKTOP\ServiceFailures.accdb`.Query1 Query1
WHERE (Query1.ORDDATfix>=?)
Apparently putting the clause in parenthesis fixed the problem.

Delete Existing Ranges in Excel Open XML

I'm working with the Open XML SDK to create an Excel document. To save time, I start with an existing document, and just make the changes I need.
To locate certain cells, my existing document defines a number of ranges. However, when I'm done I'd like to remove those ranges.
I can't seem to find any way to remove ranges from an Excel document that already has them. Any tips, suggestions or links?
Ranges are stored as defined names under the workbook element. You will need to find the defined name element based on the name you gave it in the worksheet and then delete it that way.
public void DeleteRange(WorkbooPart workbookPart, string definedNameToDelete)
{
workbookPart.Workbook.DefinedNames.Descendants<DefinedName>().First(x => x.Name == definedNameToDelete).Remove();
}
This is just a quick snippet of what you might have to do. Obviously, you might need error checking if the DefinedNames element doesn't exist or the defined named you want to delete has already been deleted, but hopefully this will point you in the right direction.
Named ranges are defined in workbook.
Look at it's api and try finding it there. Or check out MSDN.
Also, take a look at Templater. Maybe it already does what you need. Disclamer: I'm the author.

Resources