Onedrive synce issue using Power Query Editor to update download source - powerquery

I am trying to update my link to pull from my own One Drive account. I tried opening the sheet online and copying the source, and I tried copying the share link and posting it. I am still unable to make it work without getting the HTML error shown.
= Excel.Workbook(Web.Contents("https://onedrive.live.com/download?&resid=7BA5E7B92829DE18!1263"), null, true)

This works fine for me
let Source = Excel.Workbook(Web.Contents("https://onedrive.live.com/download?&resid=7BA5E7B92829DE18!1263"), null, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"ABREV", type text}, {"NICKNAME", type text}, {"Column3", type text}, {"Name", type text}, {"Standard Name", type text}, {"B", type text}, {"T", type text}, {"TEAM", type text}, {"Batting POS", type text}, {"POS", type text}, {"Standard Name_1", type text}, {"T2", type any}, {"Column13", type any}, {"Column14", type any}, {"Column15", type any}, {"Column16", type any}, {"SAVANT Table", type text}, {"Column18", type text}, {"Column19", type any}, {"Column20", type any}, {"Column21", type any}, {"Column22", type text}, {"Column23", type text}, {"Column24", type any}, {"Column25", type any}})
in #"Changed Type"

Related

Properly expand xml table nested within cell (Power Query)

I would appreciate your help on importing and expanding an XML file, with Power Query.
The XML link is here:
UN Consolidated Sanctions List
After expanding the table named ”Individual” I get a lot of tables nested within cells.
Nested Table
I tried to apply the solution offered here:
table-within-a-cell-unable-to-expand
... but nothing happens, although three steps are recorded in query settings:
Empty steps
The code in the Advanced Editor is this:
Source Query:
let
Source = Xml.Tables(Web.Contents("https://scsanctions.un.org/resources/xml/en/consolidated.xml")),
#"Expanded ENTITIES" = Table.ExpandTableColumn(Source, "ENTITIES", {"ENTITY"}, {"ENTITY"}),
#"Expanded INDIVIDUALS" = Table.ExpandTableColumn(#"Expanded ENTITIES", "INDIVIDUALS", {"INDIVIDUAL"}, {"INDIVIDUAL"})
in
#"Expanded INDIVIDUALS"
And in the referenced query:
let
Source = #"UN Source",
#"Expanded ENTITY" = Table.ExpandTableColumn(Source, "ENTITY", {"DATAID", "VERSIONNUM", "FIRST_NAME", "UN_LIST_TYPE", "REFERENCE_NUMBER", "LISTED_ON", "COMMENTS1", "LIST_TYPE", "LAST_DAY_UPDATED", "ENTITY_ALIAS", "ENTITY_ADDRESS", "SORT_KEY", "SORT_KEY_LAST_MOD", "NAME_ORIGINAL_SCRIPT", "SUBMITTED_ON"}, {"ENTITY.DATAID", "ENTITY.VERSIONNUM", "ENTITY.FIRST_NAME", "ENTITY.UN_LIST_TYPE", "ENTITY.REFERENCE_NUMBER", "ENTITY.LISTED_ON", "ENTITY.COMMENTS1", "ENTITY.LIST_TYPE", "ENTITY.LAST_DAY_UPDATED", "ENTITY.ENTITY_ALIAS", "ENTITY.ENTITY_ADDRESS", "ENTITY.SORT_KEY", "ENTITY.SORT_KEY_LAST_MOD", "ENTITY.NAME_ORIGINAL_SCRIPT", "ENTITY.SUBMITTED_ON"}),
#"Expanded INDIVIDUAL" = Table.ExpandTableColumn(#"Expanded ENTITY", "INDIVIDUAL", {"DATAID", "VERSIONNUM", "FIRST_NAME", "SECOND_NAME", "THIRD_NAME", "UN_LIST_TYPE", "REFERENCE_NUMBER", "LISTED_ON", "COMMENTS1", "DESIGNATION", "NATIONALITY", "LIST_TYPE", "LAST_DAY_UPDATED", "INDIVIDUAL_ALIAS", "INDIVIDUAL_ADDRESS", "INDIVIDUAL_DATE_OF_BIRTH", "INDIVIDUAL_PLACE_OF_BIRTH", "INDIVIDUAL_DOCUMENT", "SORT_KEY", "SORT_KEY_LAST_MOD", "NAME_ORIGINAL_SCRIPT", "FOURTH_NAME", "GENDER", "TITLE", "SUBMITTED_BY"}, {"INDIVIDUAL.DATAID", "INDIVIDUAL.VERSIONNUM", "INDIVIDUAL.FIRST_NAME", "INDIVIDUAL.SECOND_NAME", "INDIVIDUAL.THIRD_NAME", "INDIVIDUAL.UN_LIST_TYPE", "INDIVIDUAL.REFERENCE_NUMBER", "INDIVIDUAL.LISTED_ON", "INDIVIDUAL.COMMENTS1", "INDIVIDUAL.DESIGNATION", "INDIVIDUAL.NATIONALITY", "INDIVIDUAL.LIST_TYPE", "INDIVIDUAL.LAST_DAY_UPDATED", "INDIVIDUAL.INDIVIDUAL_ALIAS", "INDIVIDUAL.INDIVIDUAL_ADDRESS", "INDIVIDUAL.INDIVIDUAL_DATE_OF_BIRTH", "INDIVIDUAL.INDIVIDUAL_PLACE_OF_BIRTH", "INDIVIDUAL.INDIVIDUAL_DOCUMENT", "INDIVIDUAL.SORT_KEY", "INDIVIDUAL.SORT_KEY_LAST_MOD", "INDIVIDUAL.NAME_ORIGINAL_SCRIPT", "INDIVIDUAL.FOURTH_NAME", "INDIVIDUAL.GENDER", "INDIVIDUAL.TITLE", "INDIVIDUAL.SUBMITTED_BY"}),
#"Expanded INDIVIDUAL.DESIGNATION" = Table.ExpandTableColumn(#"Expanded INDIVIDUAL", "INDIVIDUAL.DESIGNATION", {"VALUE"}, {"INDIVIDUAL.DESIGNATION.VALUE"}),
#"Expanded INDIVIDUAL.NATIONALITY" = Table.ExpandTableColumn(#"Expanded INDIVIDUAL.DESIGNATION", "INDIVIDUAL.NATIONALITY", {"VALUE"}, {"INDIVIDUAL.NATIONALITY.VALUE"}),
#"Expanded INDIVIDUAL.LAST_DAY_UPDATED" = Table.ExpandTableColumn(#"Expanded INDIVIDUAL.NATIONALITY", "INDIVIDUAL.LAST_DAY_UPDATED", {"VALUE"}, {"INDIVIDUAL.LAST_DAY_UPDATED.VALUE"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded INDIVIDUAL.LAST_DAY_UPDATED",{"INDIVIDUAL.DATAID", "INDIVIDUAL.VERSIONNUM", "INDIVIDUAL.FIRST_NAME", "INDIVIDUAL.SECOND_NAME", "INDIVIDUAL.THIRD_NAME", "INDIVIDUAL.UN_LIST_TYPE", "INDIVIDUAL.REFERENCE_NUMBER", "INDIVIDUAL.LISTED_ON", "INDIVIDUAL.COMMENTS1", "INDIVIDUAL.DESIGNATION.VALUE"}),
Transform=Table.TransformColumns(#"Expanded INDIVIDUAL.LAST_DAY_UPDATED", {{"INDIVIDUAL.NATIONALITY.VALUE", each if Value.Is(_, type table) then _ else #table({"Item"}, {{_}} ) }} ),
ColumnsToExpand = List.Distinct(List.Combine(List.Transform(Table.Column(Transform, "INDIVIDUAL.NATIONALITY.VALUE"), each if _ is table then Table.ColumnNames(_) else {}))),
Expanded = Table.ExpandTableColumn(Transform, "INDIVIDUAL.NATIONALITY.VALUE", ColumnsToExpand, ColumnsToExpand)
in Expanded
Thank you.
Its hard to figure out even what the output should look like with all the different nested tables.
Does this work? If not provide sample desired output
let Source = Xml.Tables(Web.Contents("https://scsanctions.un.org/resources/xml/en/consolidated.xml")),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Attribute:dateGenerated", type datetimezone}}),
INDIVIDUALS = #"Changed Type"{0}[INDIVIDUALS],
INDIVIDUAL = INDIVIDUALS{0}[INDIVIDUAL],
#"Changed Type1" = Table.TransformColumnTypes(INDIVIDUAL,{{"DATAID", Int64.Type}, {"VERSIONNUM", Int64.Type}, {"FIRST_NAME", type text}, {"SECOND_NAME", type text}, {"THIRD_NAME", type text}, {"UN_LIST_TYPE", type text}, {"REFERENCE_NUMBER", type text}, {"LISTED_ON", type text}, {"COMMENTS1", type text}, {"SORT_KEY", type text}, {"SORT_KEY_LAST_MOD", type text}, {"FOURTH_NAME", type text}, {"GENDER", type text}, {"SUBMITTED_BY", type text}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"DATAID", "VERSIONNUM", "FIRST_NAME", "SECOND_NAME", "THIRD_NAME", "UN_LIST_TYPE", "REFERENCE_NUMBER", "LISTED_ON", "COMMENTS1", "SORT_KEY", "SORT_KEY_LAST_MOD", "FOURTH_NAME", "GENDER", "SUBMITTED_BY"}, "Attribute", "Value"),
Transform=Table.TransformColumns(#"Unpivoted Other Columns", {{"Value", each if Value.Is(_, type table) then _ else #table({"Item"}, {{_}} ) }} ),
ColumnsToExpand = List.Distinct(List.Combine(List.Transform(Table.Column(Transform, "Value"), each if _ is table then Table.ColumnNames(_) else {}))),
Expanded = Table.ExpandTableColumn(Transform, "Value", ColumnsToExpand, ColumnsToExpand)
in Expanded
For the other one
let Source = Xml.Tables(Web.Contents("https://scsanctions.un.org/resources/xml/en/consolidated.xml")),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Attribute:dateGenerated", type datetimezone}}),
ENTITIES = #"Changed Type"{0}[ENTITIES],
ENTITY = ENTITIES{0}[ENTITY],
#"Changed Type1" = Table.TransformColumnTypes(ENTITY,{{"DATAID", Int64.Type}, {"VERSIONNUM", Int64.Type}, {"FIRST_NAME", type text}, {"UN_LIST_TYPE", type text}, {"REFERENCE_NUMBER", type text}, {"LISTED_ON", type text}, {"COMMENTS1", type text}, {"SORT_KEY", type text}, {"SORT_KEY_LAST_MOD", type text}, {"NAME_ORIGINAL_SCRIPT", type text}, {"SUBMITTED_ON", type text}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"DATAID", "VERSIONNUM", "FIRST_NAME", "UN_LIST_TYPE", "REFERENCE_NUMBER", "LISTED_ON", "COMMENTS1", "SORT_KEY", "SORT_KEY_LAST_MOD", "NAME_ORIGINAL_SCRIPT", "SUBMITTED_ON"}, "Attribute", "Value"),
Transform=Table.TransformColumns( #"Unpivoted Columns", {{"Value", each if Value.Is(_, type table) then _ else #table({"Item"}, {{_}} ) }} ),
ColumnsToExpand = List.Distinct(List.Combine(List.Transform(Table.Column(Transform, "Value"), each if _ is table then Table.ColumnNames(_) else {}))),
Expanded = Table.ExpandTableColumn(Transform, "Value", ColumnsToExpand, ColumnsToExpand)
in Expanded

dynamoDb put item not populating all params

I have 2 lambdas that do the exact same thing, however, they are both written using different langages.
1st lambda - runs on a node.js environment, when I create my arguments to putItem, as follows:
const args = {
id: "my id",
__typename: "a type name",
_version: 1,
_lastChangedAt: now.toISOString(),
createdAt: now.toISOString(),
updatedAt: fields.LastModifiedDate
}
var recParams = {
TableName: dynamoTable,
Key: {
"id": Id
},
Item: args,
ReturnValues: "ALL_OLD"
};
and then I use the docClient to insert the row. Everything works fine, all the properties are populated in my dynamo row.
I have the exact same written in Golang:
item := RecentItem{
Id: "some Id",
_version: 1,
__typename: "a type name",
_lastChangedAt: currentTime.UTC().Format("2006-01-02T15:04:05-0700"),
createdAt: currentTime.UTC().Format("2006-01-02T15:04:05-0700"),
updatedAt: currentTime.UTC().Format("2006-01-02T15:04:05-0700"),
}
av, err := dynamodbattribute.MarshalMap(item)
input := &dynamodb.PutItemInput{
Item: av,
TableName: aws.String(tableName),
}
Everything ALMOST works, the item is inserted, but I am missing all the properties except for the id.
Structure declaration :
type RecentItem struct {
Id string `json:"id"`
_version int `json:"_version"`
_lastChangedAt string `json:"_lastChangedAt"`
createdAt string `json:"createdAt"`
updatedAt string `json:"updatedAt"`
}
Not sure why in Go my dynamoDb row is missing properties. Am I missing something?
Properties other than Id must be exported, i.e, started with an Upper case:
type RecentItem struct {
ID string `dynamodbav:"id"`
Version int `dynamodbav:"_version"`
LastChangedAt string `dynamodbav:"_lastChangedAt"`
CreatedAt string `dynamodbav:"createdAt"`
UpdatedAt string `dynamodbav:"updatedAt"`
}

Populate a struct with an array of sub-structs to turn into json

I’m trying to post some JSON. Using the JSON-to-Go tool I have this struct defined:
type IssueSetState struct {
ID string `json:"id"`
CustomFields []struct {
Value struct {
Name string `json:"name"`
} `json:"value"`
Name string `json:"name"`
Type string `json:"$type"`
} `json:"customFields"`
}
I’m trying to populate it with some data that I can then pass into the http library:
jsonValues := &IssueSetState{
ID: resultEntityId.ID,
CustomFields: []{
Value: {
Name: "Fixed",
},
Name: "State",
Type: "StateIssueCustomField",
},
}
jsonEncoded := new(bytes.Buffer)
json.NewEncoder(jsonEncoded).Encode(jsonValues)
I keep getting errors like:
./main.go:245:19: syntax error: unexpected {, expecting type
./main.go:246:9: syntax error: unexpected :, expecting comma or }
./main.go:249:8: syntax error: unexpected : at end of statement
./main.go:251:4: syntax error: unexpected comma after top level declaration
I’m sure the mistake I’m making is a simple one, but I’m new to Go.
One possible way is to define named structs for every anonymous struct you have.
type IssueSetState struct {
ID string `json:"id"`
CustomFields []CustomField `json:"customFields"`
}
type CustomField struct {
Value Value `json:"value"`
Name string `json:"name"`
Type string `json:"type"`
}
type Value struct {
Name string `json:"name"`
}
Now you can create it like this:
IssueSetState{
ID: resultEntityId.ID,
CustomFields: []CustomField{
{
Value: Value{
Name: "Fixed",
},
Name: "State",
Type: "StateIssueCustomField",
},
{
Value: Value{
Name: "Fixed",
},
Name: "State",
Type: "StateIssueCustomField",
},
},
}
So you're initializing the jsonValue badly.
You can fix it in 2 ways:
https://play.golang.org/p/LFO4tOLyG60
making structures flat
https://play.golang.org/p/TyFfaMf7XeF
by repeating the structure definition when declaring value
The first one should be easier and clearer.

Why am I getting an error when assigning a correct type?

Recently I started experimenting with Go, but I hit on hard rock.
I have this type:
type LocationType string
const (
River LocationType = "River"
Mountain LocationType = "Mountain"
)
func (t LocationType) ToString() string {
return string(t)
}
I also have this one:
type LocationCreateInput struct {
Name string `json:"name,omitempty"`
Type *models.LocationType `json:"type,omitempty"`
}
Now I'm trying to create a new LocationCreateInput variable:
input := &gqlModels.LocationCreateInput {
Name: "Test name",
Type: models.River
}
and I am getting the below error:
Cannot use 'models.Site' (type LocationType) as the type *models.LocationType
Can somebody point me to the right way of assigning the Type value? In the end, it is just a string.
What am I missing here? Could you give me a push?
You are trying to assign a value to a pointer type. So it's not "just a string", it's a "a pointer to just a string".
Either you change the type of the struct field from *models.LocationType to models.LocationType, or you need to take the address when assigning:
val := models.River
input := &gqlModels.LocationCreateInput {
Name: "Test name",
Type: &val,
}

How to recall this struct?

how to recall this stryc?
struct User {
var name: String
var street: String
var city: String
var postalCode: String
func printAddress() -> String {
return """
\(name)
\(street)
\(city)
\(postalCode)
"""
}
}
I expect to have an address in different lines like the method, for example
Well Smith
streetnumber this one
lalaland
19890
but result comes back in struct form
Not sure what you mean with "recall struct" but if you want to print it in the expected format simply use printAddress()
let user = User(name: "name", street: "street", city: "city", postalCode: "postalCode")
print(user.printAddress())
Output:
name
street
city
postalCode

Resources