SharePoint autogenerated JSON formatting and use of operator or field choice not working - json

I did a search on this topic and I am not that JSON familiar, so I thought I'd see if I can find the answer here to my question from the community.
I have a view from a list that I am formatting in SharePoint (SP) that creates some automated JSON. It simply colors the items based on if the value matches in the generated JSON code. I am trying to tweak it but having trouble getting the format to come up as a match.
I am trying to use just the one column called Display. It's a calculated field which concatenates a bunch of string text.
Here is what the generated section of code from SP I am trying to tweak looks like (this is not all of it):
{ "operator": "==",
"operands": [
"[$Display]",
"LOCATED"
]
}, =if(#isSelected == "true" etc...
So the formatting will happen if the data in field Display = LOCATED returning true and will apply the formatting. What I am trying to do, is get some sort of string contains or wild card matching.
The contents of the field Display in the SP list will contain something dynamic and possibly the word LOCATED somewhere in the text.
So ideally I'd like to tweak this code to return true for the formatting if the Display field content said something like "John Doe LOCATED New York" for example.
if anyone has any ideas how I could solve this that would be great. Also I was trying another field which is a choice field for exact matching but I couldn't get it to work either.
Thanks.

This issue has been resolved, by doing an exact field match instead of wildcarding.

Related

Adding new field to each JSON Object

I am currently doing a project and I have a huge json list with schools in my country I would like to add one more field to each object, is there any website to do this, without typing it manually?
There are many ways you can achieve this.
First, I am assuming you are dealing with what is known as a json array which looks like this
[{name:"John", age:31, city:"New York"},
{name:"Jim", age:27, city:"London"},
{name:"Jeff", age:80, city:"Dublin"}]
You could simply use a program such as Notepad++ & do a search/replace Ctrl+h.
Find what: }
Replace with: , mynewfield: ""}
This method will replace all instances of an ending curly bracket (end of a json object) with a new field & value of your choice. So essentially, its just appending a new field for each object.
An alternative way that is also very useful when dealing with large data is with "regular expressions" (or regex expressions). The use case here for using a regex expression could be if you didn't want to add your new field to the end of each object but, somewhere in the middle (like before/after age).
In the case, you could use
Find what: (?<=,)(.*)(?=age) (or (?<=,)(.*)(?=city))
Replace with: mynewfield: "",
NOTE: For regex expressions you must have them enabled under the "Search Mode" after clicking control+h.

Extract comma-separated values from JSON Records within a List with PowerQuery

As part of a tool I am creating for my team I am connecting to an internal web service via PowerQuery.
The web service returns nested JSON, and I have trouble parsing the JSON data to the format I am looking for. Specifically, I have a problem with extracting the content of records in a column to a comma separated list.
The data
As you can see, the data contains details related to a specific "race" (race_id). What I want to focus on is the information in the driver_codes which is a List of Records. The amount of records varies from 0 to 4 and each record is structured as id: 50000 (50000 could be any 5 digit number). So it could be:
id: 10000
id: 20000
id: 30000
As requested, an example snippet of the raw JSON:
<race>
<race_id>ABC123445</race_id>
<begin_time>2018-03-23T00:00:00Z</begin_time>
<vehicle_id>gokart_11</vehicle_id>
<driver_code>
<id>90200</id>
</driver_code>
<driver_code>
<id>90500</id>
</driver_code>
</race>
I want it to be structured as:
10000,20000,30000
The problem
When I choose "Extract values" on the column with the list, then I get the following message:
Expression.Error: We cannot convert a value of type Record to type
Text.
If I instead choose "Expand to new rows", then duplicate rows are created for each unique driver code. I now have several rows per unique race_id, but what I wanted was one row per unique race_id and a concatenated list of driver codes.
What I have tried
I have tried grouping the data by the race_id, but the operations allowed when grouping data do not include concatenating rows.
I have also tried unpivoting the column, but that leaves me with the same problem: I still get multiple rows.
I have googled (and Stack Overflowed) this issue extensively without luck. It might be that I am using the wrong keywords, however, so I apologize if a duplicate exists.
UPDATE: What I have tried based on the answers so far
I tried Alexis Olson's excellent and very detailed method, but I end up with the following error:
Expression.Error: We cannot convert the value "id" to type Number. Details:
Value=id
Type=Type
The error comes from using either of these lines of M code (one with a List.Transform and one without):
= Table.Group(#"Renamed Columns", {"race_id", "begin_time", "vehicle_id"},
{{"DriverCodes", each Text.Combine([driver_code][id], ","), type text}})
= Table.Group(#"Renamed Columns", {"race_id", "begin_time", "vehicle_id"},
{{"DriverCodes", each Text.Combine(List.Transform([driver_code][id], each Number.ToText(_)), ","), type text}})
NB: if I do not write [driver_code][id] but only [id] then I get another error saying that column [id] does not exist.
Here's the JSON equivalent to the XML example you gave:
{"race": {
"race_id": "ABC123445",
"begin_time": "2018-03-23T00:00:00Z",
"vehicle_id": "gokart_11",
"driver_code": [
{ "id": "90200" },
{ "id": "90500" }
]}}
If you load this into the query editor, convert it to a table, and expand out the Value record, you'll have a table that looks like this:
At this point, choose Expand to New Rows, and then expand the id column so that your table looks like this:
At this point, you can apply the trick #mccard suggested. Group by the first columns and aggregate over the last using, say, max.
This last step produces M code like this:
= Table.Group(#"Expanded driver_code1",
{"Name", "race_id", "begin_time", "vehicle_id"},
{{"id", each List.Max([id]), type text}})
Instead of this, you want to replace List.Max with Text.Combine as follows:
= Table.Group(#"Changed Type",
{"Name", "race_id", "begin_time", "vehicle_id"},
{{"id", each Text.Combine([id], ","), type text}})
Note that if your id column is not in the text format, then this will throw an error. To fix this, insert a step before you group rows using Transform Tab > Data Type: Text to convert the type. Another options is to use List.Transform inside your Text.Combine like this:
Text.Combine(List.Transform([id], each Number.ToText(_)), ",")
Either way, you should end up with this:
An approach would be to use the Advanced Editor and change the operation done when grouping the data directly there in the code.
First, create the grouping using one of the operations available in the menu. For instance, create a column"Sum" using the Sum operation. It will give an error, but we should get the starting code to work on.
Then, open the Advanced Editor and find the code corresponding to the operation. It should be something like:
{{"Sum", each List.Sum([driver_codes]), type text}}
Change it to:
{{"driver_codes", each Text.Combine([driver_codes], ","), type text}}

having a bit of trouble trying to match fields and add fields to the matched ones

So ive been busting my brain for weeks. so id like to know that in MongoDB i have a table, so in this table there are multiple json objects, all objects have the same fields in, so what im trying to achieve is: match all doctuments by a specific set of ids eg "id": "1234" id like to match a specific fiel in all json objects and then add in another field just for those who match the search.. any ideas?
Although I am not fully clear about your question, but from whatever I understood,you can use $aggregate to solve your problem.
Refer to the below link->
https://docs.mongodb.com/v3.2/reference/method/db.collection.aggregate/

Access - Searching for a value

I am trying to display a word in a field if another field displays something.
Say I have two fields called [Fruit] and [Description]
in [Fruit] would be
RApple
GApple
if [Fruit] states "RApple" I want the [Description] to read "Red Apple" - also would the [Description] save back to the table?
I have tried IIf and I can't get that to work.
I have the same thing working in Excel using ISNUMBER and SEARCH
=IF(ISNUMBER(SEARCH("RApple",B1)),"Red Apple",IF(ISNUMBER(SEARCH("GApple",B1)),"Green Apple")
Can something like this work in Access?
Well, if we were simply testing 2 strings and they were always in that format you provided, it could be as simple as :
IIf([color] = "RApple", "Red Apple", IIf([color] = "GApple", "Green Apple", "No Match"))
To search for the color :
IIf(Left([Fruit],1)="R","Red",IIf(Left([Fruit],1)="G","Green","No Match"))
This would all be better off in VBA, however given the context of your question, it doesn't sound like it's in scope, since this seems like a simple test.
I also agree with #HansUp in stating that this is a bad design with your data. When you can, you want to avoid prying logic out of strings. It would be much better with two fields: [Color] and [Fruit]. From there, you could make the string you so desire if you needed to (RApple, etc.)

Googlechart error on a linechart with tooltip values coming via JSON

I have a google chart and want to add a custom tooltip. I found some great answers like this this site and set about doing this with roles. I also found this link about it and it looked like the best way.
My data is being generated via json and I use a php file to create a json feed. The rows I have coded like this
{"cols": [ {"id":"","label":"Period","pattern":""},
{"id":"","label":"Recorded P/L","type":"number", "role":"data"} ,
{"id":"","label": null,"type":"string", "role":"tooltip"},
{"id":"","label":"Best Available P/L","type":"number", "role":"data"},
{"id":"","label": null,"type":"string", "role":"tooltip"}
]
Then it goes on and adds all the data. The problem is when I try to run this I get the error
All series on a given axis must be of the same data type
I have checked the json and that is formed correctly but am not sure what I could be doing wrong.
At least part of your problem is that you're not specifying the type for your first column.