Is power bi has a functional to input whole column in function instead of one cell from column?example with single cell and I got this result result of calculation. But is it possible to input whole column in that function?
Yes, you can do this. You can pass in a list and return a table
Example:
let Source = (ColumnData as list) => let
#"returnTable" = Table.FromList(ColumnData )
in #"returnTable"
in Source
This you can make as your own customer function and call it from other scripts
Be careful to not create a circ. reference.
The way to solve this:
MyList = #"Your Table"[TYPE],
#"Invoked Custom Function" = Table.AddColumn(#"Changed Type", "Convert", each Convert(MyList))
Related
Scala beginner who is trying to store values obtains in a Scala foreach loop but failing miserably.
The basic foreach loop looks like this currently:
order.orderList.foreach((x: OrderRef) => {
val references = x.ref}))
When run this foreach loop will execute twice and return a reference each time. I'm trying to capture the reference value it returns on each run (so two references in either a list or array form so I can access these values later)
I'm really confused about how to go about doing this...
I attempted to retrieve and store the values as an array but when ran, the array list doesn't seem to hold any values.
This was my attempt:
val newArray = Array(order.orderList.foreach((x: OrderRef) => {
val references = x.ref
}))
println(newArray)
Any advice would be much appreciated. If there is a better way to achieve this, please share. Thanks
Use map instead of foreach
order.orderList.map((x: OrderRef) => {x.ref}))
Also val references = x.ref doesn't return anything. It create new local variable and assign value to it.
Agree with answer 1, and I believe the reason is below:
Return of 'foreach' or 'for' should be 'Unit', and 'map' is an with an changed type result like example below:
def map[B](f: (A) ⇒ B): Array[B]
Compare To for and foreach, the prototype should be like this
def foreach(f: (A) ⇒ Unit): Unit
So If you wanna to get an changed data which is maped from your source data, considering more about functions like map, flatMap, and these functions will traverse all datas like for and foreach(except with yield), but with return values.
I'm using Slick with Play but am having some problems when trying to update a column value as it is not being updated, although I don't get any error back.
I have a column that tells me if the given row is selected or not. What I want to do is to get the current selected value (which is stored in a DB column) and then update that same column to have the opposite value. Currently (after many unsuccessful attempts) I have the following code which compiles and runs but nothing happens behind the scenes:
val action = listItems.filter(_.uid === uid).map(_.isSelected).result.map { selected =>
val isSelected = selected.head
println(s"selected before -> $isSelected")
val q = for {li <- listItems if li.uid === uid} yield li.isSelected
q.update(!isSelected)
}
db.run(action)
What am I doing wrong (I am new to slick so this may not make any sense at all!)
this needs to be seperate actions: one read followed by an update. Slick allows composition of actions in a neat way:
val targetRows = listItems.filter(_.uid === uid).map(_.isSelected)
val actions = for {
booleanOption <- targetRows.result.headOption
updateActionOption = booleanOption.map(b => targetRows.update(!b))
affected <- updateActionOption.getOrElse(DBIO.successful(0))
} yield affected
db.run(actions)
Update:
Just as a side note, RDBMSs usually facilitate constructs for performing updates in one database roundtrip such as updating a boolean column to it's opposite value without needing to read it first and manually negate it. This would look like this in mysql forexample:
UPDATE `table` SET `my_bool` = NOT my_bool
but to my knowledge the high level slick api doesn't support this construct. hence the need for two seperate database actions in your case. I myself would appreciate it if somebody proved me wrong.
I have a stored procedure in SQL Server:
Create PROCEDURE SPLogCountInUser
(#ManegerID int)
AS
SELECT COUNT(*) AS LogDone
FROM vw_UserApprove
WHERE UserMasterID = #ManegerID AND UserState = 0
I want to use this procedure to show me the output of this stored procedure in my WPF Entity Framework.
I have a label in my WPF window that I want it to show me the out put of above procedure. My code is like this, but it does not work:
HadishDataBaseEntities database = new HadishDataBaseEntities();
var All = database.SPLogCountInUser(HadishCode.gUserID);
lbl_Log.Content = All.ToList();
What does "not work" mean? Are you getting a compilation error, a runtime exception or just an unexpected result? Please always specify this when you aska question.
And what's the return type of your SPLogCountInUser method? If it is an IEnumerable, you could set the Content property of the Label to the string representation of the first item:
HadishDataBaseEntities database = new HadishDataBaseEntities();
var All = database.SPLogCountInUser(HadishCode.gUserID).ToList();
if(All != null && All.Count > 0)
lbl_Log.Content = All[0].ToString();
You can do that like this:
HadishDataBaseEntities database = new HadishDataBaseEntities();
var All = database.Database.SqlQuery<int>("SPLogCountInUser #ManegerID", HadishCode.gUserID);
lbl_Log.Content = All.First(); //Your stored procedure will always return one row, so we don't need ToList(), additionally the label will not show the actual value if you set its content to a List.
I think .ToList(); must be added if you want your SP get some meanful value.
I made such mistake by missing .ToList() and failed to get anything even though I know the SQL invoke is correct.
But after adding .ToList(); then return value is a List and you can find your value.
My goal is to pass in a YouTube channel's id and call that channel's video view metrics for a given window of time, store that data in an array and then pass each video view metric into one column of array.length in descending order.
//...key variables
var channelId = sheet.getActiveCell().getValue();
var offsetCell = sheet.getActiveCell().offset(0,2);
//further down the script...
for(i=0; i < dataResponse.items.length; i++) {
var data = [];
var vidDataLen = dataResponse.items.length;
var offsetRange = sheet.getRange(offsetCell, vidDataLen, 0)
data.push(dataResponse.items[i].statistics.viewCount);
//sheet.appendRow(data)
offsetCell.setValue([data])
}
As you can follow, I initially used appendRow, but I didn't want data to be appended into overwriting rows, I wanted the data to pass into, the column and row of offsetCell, and descending into the succeeding cells.
My efforts with
var offsetRange = sheet.getRange(offsetCell, vidDataLen, 0)
were attempting to create an active range based on the number of items in the data array, since that will vary on each channel.
However, that did not work, because getRange does not accept objects as parameters.
Are there any google-script functions I could use to pass the array data into an offset cell and successive cells in that same column?
NOTE: Running this script with the offsetRange variable commented out results in the YouTube api being successfully called, however, only one value from the 'data' array is passed into offsetCell
NOTE 2: I have scoured StackOverflow for google scripted questions and related subjects, however I have not seen an active or relevant solution for passing multiple stored values from an API call into a specific range of offset cells (in one column).
The solution for this was relatively straight forward
I removed the data array and used the statement sheet.insertRows(offsetCell.getRow()+1,vidDataLen);
to create the range of cells in the column I wanted to pass data into so existing data would not be overwritten
var vidDataLen = dataResponse.items.length;
sheet.insertRows(offsetCell.getRow()+1,vidDataLen);
for(i=0; i < dataResponse.items.length; i++) {
offsetCell.setValue(dataResponse.items[i].statistics.viewCount);
offsetCell = offsetCell.offset(1, 0);
}
Instead of passing data into a loop array, I just passed each value directly into the setValue() method's argument, and then assigned offsetCell to offsetting each new iteration of offsetCell by 1 row and 0 columns.
I've been searching for hours but I couldn't find an answer to my question: I've set up a ListGrid similar to the one shown here (Link). Right now I am using a XML-File as data source (default rows) just like in the example. It is also possible to add and delete rows to/from the grid.
Therefore I would like to store every user's data from the grid in a data store (Google Datastore). So I need to read all the rows of the current user as Strings. What would be a good way to do that? I already tried the following, but without success:
ListGrid componentsGrid = new ListGrid();
componentsGrid.setWidth(500);
componentsGrid.setHeight(224);
componentsGrid.setCellHeight(22);
componentsGrid.setDataSource(ComponentsXmlDS.getInstance());
componentsGrid.setAutoFetchData(true);
componentsGrid.setCanEdit(true);
componentsGrid.setModalEditing(true);
componentsGrid.setEditEvent(ListGridEditEvent.CLICK);
componentsGrid.setListEndEditAction(RowEndEditAction.NEXT);
componentsGrid.setAutoSaveEdits(false);
layout.addMember(componentsGrid);
//First try
componentsGrid.fetchData();
logger.log(Level.INFO, "Components: "+ componentsGrid.getResultSet().get(0).getAttribute("componentType"));
//Second try
logger.log(Level.INFO, "Components: "+ componentsGrid.getAllFields());
// Third try
logger.log(Level.INFO, "Components: "+ componentsGrid.getRecords());
Anyone having a hint? Help is greatly appreciated.
If I understand well your requirement you want to read all the rows of the grid and store their data in a db.
I think you can use:
getRecordList() which *Return the underlying data of this DataBoundComponent as a RecordList.
You will be able to iterate inside this list, extract the attribute value you want for every record and store these data in your db.
Or use the getRecords() method as you said and iterate in the array of ListGridRecord obtained.
To iterate through your RecordList you have to transform it to an array, for example with a lot of dummy objects and methods:
RecordList data = MyGrid.getRecordList();
for(Record record : data.toArray()){
MyDataObject obj = new MyDataObject()
obj.setId(record.getAttribute("thId"));
obj.setOne(record.getAttribute("anAttribute"));
obj.setTwo(record.getAttribute("anotherAttribute"));
obj.StoreToDb();
}