Vlookup but return sheet name if found - google-sheets

Currently, this will return "Yes" (which is in the 6th column) or "Not Found". Would it be possible to return the sheet name if true?
Thanks in advance.
=IFERROR(VLOOKUP(A2,IMPORTRANGE("1eMzpzOJBDmrJfxqHTqEcllK8lFIN8C8fSkQUpZY1gJM", "Current Roster (Master)!A2:H"),6,false),
IFERROR(VLOOKUP(A2,IMPORTRANGE("179IscQOWpn7W1GPH5RSK4sc8zxUS2Ll3AoIwkxEPOX4", "Current Roster (Master)!A2:H"),6,false),
IFERROR(VLOOKUP(A2,IMPORTRANGE("1Xv0cjLgT_20ETSsWL031ybSvqG3onZlKMYXrLWiR1vc", "Current Roster (Master)!A2:H"),6,false),
IFERROR(VLOOKUP(A2,IMPORTRANGE("1Yjp-AVuuKYMNonUADc37h0CInN9cr7GCnxx0wIwoaY4", "Current Roster (Master)!A2:H"),6,false),
IFERROR(VLOOKUP(A2,IMPORTRANGE("1d1rGCzi8W975i__wZ-7RcuXMmWFXYjg5sZTceLDjgRw", "Current Roster (Master)!A2:H"),6,false),
IFERROR(VLOOKUP(A2,IMPORTRANGE("1ve8EAw3OMf_xRofRgRa6vBPGA3P72Gk8E77yrGFXyF8", "Current Roster (Master)!A2:H"),6,false),
IFERROR(VLOOKUP(A2,IMPORTRANGE("17-NKDd-WCO_XE0zXEwEcZ8CGHrB_cRIHg7wHnMnrIt4", "Current Roster (Master)!A2:H"),6,false),
IFERROR(VLOOKUP(A2,IMPORTRANGE("1bI2W5b3-WlgLe401enLpt9hqqjxvD41zMsU2gSGUsaQ", "Current Roster (Master)!A2:H"),6,false),
IFERROR(VLOOKUP(A2,IMPORTRANGE("1Zn75yae3XVhXxQEDLuG3gCZjkce2HDcxUaVDEfJmgck", "Current Roster (Master)!A2:H"),6,false), "Not Found")))))))))

if all sheet names are same just use:
=SUBSTITUTE(
IFERROR(VLOOKUP(A2, IMPORTRANGE("1eMzpzOJBDmrJfxqHTqEcllK8lFIN8C8fSkQUpZY1gJM",
"Current Roster (Master)!A2:H"), 6, ),
IFERROR(VLOOKUP(A2, IMPORTRANGE("179IscQOWpn7W1GPH5RSK4sc8zxUS2Ll3AoIwkxEPOX4",
"Current Roster (Master)!A2:H"), 6, ),
IFERROR(VLOOKUP(A2, IMPORTRANGE("1Xv0cjLgT_20ETSsWL031ybSvqG3onZlKMYXrLWiR1vc",
"Current Roster (Master)!A2:H"), 6, ),
IFERROR(VLOOKUP(A2, IMPORTRANGE("1Yjp-AVuuKYMNonUADc37h0CInN9cr7GCnxx0wIwoaY4",
"Current Roster (Master)!A2:H"), 6, ),
IFERROR(VLOOKUP(A2, IMPORTRANGE("1d1rGCzi8W975i__wZ-7RcuXMmWFXYjg5sZTceLDjgRw",
"Current Roster (Master)!A2:H"), 6, ),
IFERROR(VLOOKUP(A2, IMPORTRANGE("1ve8EAw3OMf_xRofRgRa6vBPGA3P72Gk8E77yrGFXyF8",
"Current Roster (Master)!A2:H"), 6, ),
IFERROR(VLOOKUP(A2, IMPORTRANGE("17-NKDd-WCO_XE0zXEwEcZ8CGHrB_cRIHg7wHnMnrIt4",
"Current Roster (Master)!A2:H"), 6, ),
IFERROR(VLOOKUP(A2, IMPORTRANGE("1bI2W5b3-WlgLe401enLpt9hqqjxvD41zMsU2gSGUsaQ",
"Current Roster (Master)!A2:H"), 6, ),
IFERROR(VLOOKUP(A2, IMPORTRANGE("1Zn75yae3XVhXxQEDLuG3gCZjkce2HDcxUaVDEfJmgck",
"Current Roster (Master)!A2:H"), 6, ), "Not Found"))))))))),
"Yes", "Current Roster (Master)")
update:
=IFERROR(SUBSTITUTE(VLOOKUP(A2, IMPORTRANGE("1eMzpzOJBDmrJfxqHTqEcllK8lFIN8C8fSkQUpZY1gJM", "Current Roster (Master)!A2:H"), 6, ), "yes", "1st"),
IFERROR(SUBSTITUTE(VLOOKUP(A2, IMPORTRANGE("179IscQOWpn7W1GPH5RSK4sc8zxUS2Ll3AoIwkxEPOX4", "Current Roster (Master)!A2:H"), 6, ), "yes", "2nd"),
IFERROR(SUBSTITUTE(VLOOKUP(A2, IMPORTRANGE("1Xv0cjLgT_20ETSsWL031ybSvqG3onZlKMYXrLWiR1vc", "Current Roster (Master)!A2:H"), 6, ), "yes", "3rd"),
IFERROR(SUBSTITUTE(VLOOKUP(A2, IMPORTRANGE("1Yjp-AVuuKYMNonUADc37h0CInN9cr7GCnxx0wIwoaY4", "Current Roster (Master)!A2:H"), 6, ), "yes", "xxx"),
IFERROR(SUBSTITUTE(VLOOKUP(A2, IMPORTRANGE("1d1rGCzi8W975i__wZ-7RcuXMmWFXYjg5sZTceLDjgRw", "Current Roster (Master)!A2:H"), 6, ), "yes", "ccc"),
IFERROR(SUBSTITUTE(VLOOKUP(A2, IMPORTRANGE("1ve8EAw3OMf_xRofRgRa6vBPGA3P72Gk8E77yrGFXyF8", "Current Roster (Master)!A2:H"), 6, ), "yes", "123"),
IFERROR(SUBSTITUTE(VLOOKUP(A2, IMPORTRANGE("17-NKDd-WCO_XE0zXEwEcZ8CGHrB_cRIHg7wHnMnrIt4", "Current Roster (Master)!A2:H"), 6, ), "yes", "999"),
IFERROR(SUBSTITUTE(VLOOKUP(A2, IMPORTRANGE("1bI2W5b3-WlgLe401enLpt9hqqjxvD41zMsU2gSGUsaQ", "Current Roster (Master)!A2:H"), 6, ), "yes", "9th"),
IFERROR(SUBSTITUTE(VLOOKUP(A2, IMPORTRANGE("1Zn75yae3XVhXxQEDLuG3gCZjkce2HDcxUaVDEfJmgck", "Current Roster (Master)!A2:H"), 6, ), "yes", "♥♥♥"),
"Not Found")))))))))

Related

ArgumentError when trying to save multiple records in Rails

What we want to achieve
I am sending an array from Nuxt.js, Rails is in API mode and I am getting an error when I try to retrieve and save the array contents one by one.
I want to save the array received by params and add multiple records.
Error
ArgumentError (When assigning attributes, you must pass a hash as an argument, Array passed.):
Code
Controller
def create
schedule = Schedule.new(post_params)
if schedule.save
render json: schedule, status: :created
else
render json: schedule, status: :internal_server_error
end
end
def post_params
params.require(:post).map do |schedule|
schedule.permit(:id, :name, :start, :end, :color, :timed, :long_time, :post_id, :post_item_id)
end
end
parameter
post: [,…]
0: {name: "", color: "#2196F3", start: 1648275300000, end: 1648276200000, timed: true, long_time: true}
1: {name: "", color: "#2196F3", start: 1648361700000, end: 1648362600000, timed: true, long_time: true}
2: {name: "", color: "#2196F3", start: 1648448100000, end: 1648449000000, timed: true, long_time: true}
3: {name: "", color: "#2196F3", start: 1648534500000, end: 1648535400000, timed: true, long_time: true}
4: {name: "", color: "#2196F3", start: 1648620900000, end: 1648621800000, timed: true, long_time: true}
What we tried
・I tried to retrieve a value using map.
・I tried to convert it to a hash using to_h at the end of pemit, but neither the value nor the error changed.
Well first question here is what is happening if one of the records failed, do previously created should be rollbacked and following actions to be aborted or you just ignore invalid creations.
In case of rollback/aborting you can go for Schedule.create!(post_params) - responding with the proper message error and all others will be rollbacked.
In case of ignoring failure ones, go for Schedule.create!(post_params) - responding with created and failure ones.

Ruby on Rails Seed Data

I am Ruby/Rails newbie. I am currently learning about the Rails console and databases using Rake and the seeds.rb file.
I am supposed to:
Add a post with a unique title and body to seeds.rb.
Before creating a unique post, verify it exists in the database. Only
seed the post if it doesn't.
Run rake db:seed a couple times, start your Rails console and confirm
that your unique post has only been seeded once.
Repeat to create a unique comment and confirm that it is also only
seeded once.
Honestly I don't know how to start working on this. I am supposed to add a post using the rails console or directly from the seeds.rb file? Any guidance will be greatly appreciated.
Despite the intention of seed-ing - that this is meant to be run once, to populate the database - there is no technical constrain preventing you from running rake db:seed command couple times. Even without cleaning/recreating your database.
In that case, try following code for db/seeds.rb
post_atrributes = [
{ title: "Sample Title 1", body: "Sample body 1" },
{ title: "Sample Title 2", body: "Sample body 2" },
{ title: "Sample Title 3", body: "Sample body 3" },
]
post_attributes.each do |attributes|
Post.create(attributes) unless Post.where(attributes).first
end
First of all, we're defining an array of attributes for each Post, to be created.
Later, we're iterating through that array (with post_attributes.each do |attributes|), and trying create a new Post, unless one with specified attributes found.
In Rails, there is quite fancy method first_or_create, which does exactly that - queries database for specified attributes (where(attributes)), and if nothing found - creates new record based on provided attributes.
post_atrributes = [
{ title: "Sample Title 1", body: "Sample body 1" },
{ title: "Sample Title 2", body: "Sample body 2" },
{ title: "Sample Title 3", body: "Sample body 3" },
]
post_attributes.each do |attributes|
Post.where(attributes).first_or_create
end
At this point, you can "seed" the database with rake db:seed and check what is stored in database (after running rails console) by:
Post.all.map(&:title)
Assuming you had empty database before running rake db:seed, it should contain only 3 Posts. The ones specified with attributes in post_attributes.
Now, if you try to modify your db/seeds.rb again, adding an attributes for one more Post:
post_atrributes = [
{ title: "Sample Title 1", body: "Sample body 1" },
{ title: "Sample Title 2", body: "Sample body 2" },
{ title: "Sample Title 3", body: "Sample body 3" },
{ title: "Another Post", body: "WOW!" },
]
post_attributes.each do |attributes|
Post.where(attributes).first_or_create
end
After running rake db:seed, and checking in console:
Post.all.map(&:title)
You can see, that only one new Post has been created. The one with title "Another Post".
In your question I understood, that when creating new Post, both attributes - title and body have be unique, so if you try to perform the same for attributes like:
post_atrributes = [
{ title: "Sample Title 1", body: "Sample body 1" },
{ title: "Sample Title 1", body: "Sample body 2" },
]
This will create two separate Posts, because they have different body attributes defined.
For Comments you can do similar thing.
Again, as jBeas mentioned earlier - seed-ing has different purpose, but if this is only exercise to play with ActiveRecord - this is one of ways how you can tackle the problem.
Hope that helps!
Seeding is the process of populating a database with data.
There are two methods used to accomplish this.
You can use ActiveRecord Migrations
class AddInitialProducts < ActiveRecord::Migration
def up
5.times do |i|
Product.create(name: "Product ##{i}", description: "A product.")
end
end
def down
Product.delete_all
end
end
Or you can store it in a separate seeds.rb file
5.times do |i|
Product.create(name: "Product ##{i}", description: "A product.")
end
afterwards, run rake db:seed
Source
http://edgeguides.rubyonrails.org/active_record_migrations.html#migrations-and-seed-data

Update an array of object using CouchRest, Rails

Im trying to update a parameter in a collection of objects using Rails, CouchRest.
This is what im doing currently,
class User
property :country
property :some_flag
end
#users = User.by_country(:key => 'country-name')
#users.each do |user|
user.update_attributes({:some_flag => 'true'})
end
Whenever update_attributes failed for a User object i want the entire transaction to be rolled back. How can i achieve this?
Am Using CouchDB. Rails, CouchRest and Not using ActiveRecord.
CouchDB doesn't explicitly support transaction, but there is something called "bulk update" which may be of help:
http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API#Modify_Multiple_Documents_With_a_Single_Request
Example data for the update:
{
"all_or_nothing": true,
"docs": [
{"_id": "0", "_rev": "1-62657917", "integer": 10, "string": "10"},
{"_id": "1", "_rev": "2-1579510027", "integer": 2, "string": "2"},
{"_id": "2", "_rev": "2-3978456339", "integer": 3, "string": "3"}
]
}

How do I create a user with no email address in Desire2Learn's Valence APIs?

If I want to create a new user through Desire2Learn's Valence API, but the user will not have an external email address, how must I provide the new user data?
When you create a new user, you must use the User.CreateUserData structure, and if you want the user to have no external email address, you have to provide a null value for the property:
{"UserName": "Test.User",
"FirstName": "Test",
"MiddleName": "",
"LastName": "User",
"RoleId": "103",
"OrgDefinedId": "ext-test-user",
"IsActive": true,
"ExternalEmail": null,
"SendCreationEmail": false}

Build json from ValueObjects in Rails 3?

i was wondering how i can build a json response from a value object?
Situation?
I want to return clear json, only the field i need in the front-end. Which means: All associations should be included in the json. But again: only the fields I need. This i why i would like to use a special value object (defining the field) on top of my models.
Problem?
Is this a good idea? How to build value objects (VOs) with rails?
Thanks for helping
Of course it's possible. Look here:
Here is an example:
konata.to_json(:only => [ :id, :name ])
# => {"id": 1, "name": "Konata Izumi"}
As you're talking about associations:
konata.to_json(:include => :posts)
# => {"id": 1, "name": "Konata Izumi", "age": 16,
"created_at": "2006/08/01", "awesome": true,
"posts": [{"id": 1, "author_id": 1, "title": "Welcome to the weblog"},
{"id": 2, author_id: 1, "title": "So I was thinking"}]}
This one sounds interesting:
http://fabrik42.github.com/acts_as_api/

Resources