Related
I have this json data in AWS S3, it's an array of objects.
[{"usefulOffer": "Nike shoe","webStyleId": "123","skus": [{"rmsSkuId": "456","eventIds": ["", "7", "8", "9"]},{"rmsSkuId": "777","eventIds": ["B", "Q", "W", "H"]}],"timeStamp": "4545"},
{"usefulOffer": "Adidas pants","webStyleId": "35","skus": [{"rmsSkuId": "16","eventIds": ["2", "4", "boo", "la"]}],"timeStamp": "999"},...]
This is a query how I created table/schema in Athena for data above
CREATE EXTERNAL TABLE IF NOT EXISTS table (
usefulOffer STRING,
webStyleId STRING,
skus array<struct<rmsSkuId: STRING, eventIds: array<STRING>>>,
`timeStamp` STRING
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
WITH SERDEPROPERTIES ('ignore.malformed.json' = 'true')
LOCATION 's3://...'
When I make a query to Athena using athena-express 'SELECT * FROM table' it returns the nice json format except the nested array it returns as a string
[
{
usefuloffer: 'Nike shoe',
webstyleid: '123',
skus: '[{rmsskuid=456, eventids=[, 7, 8, 9]}, {rmsskuid=777, eventids=[B, Q, W, H]}]',
timestamp: '4545'
},
{
usefuloffer: 'Adidas pants',
webstyleid: '35',
skus: '[{rmsskuid=16, eventids=[2, 4, boo, la]}]',
timestamp: '999'
},
I was trying create the table/schema without this option "WITH SERDEPROPERTIES ('ignore.malformed.json' = 'true')" but it returned me bad format at all.
How can I get the nested array as array but not as a string?
Thank you for help!
I have a hierarchical matrix with a corresponding chart from this table:
let
t0 = Table.FromRows(
{
{"2020-01-01", "1", "10", 10},
{"2020-01-02", "1", "10", 3},
{"2020-01-01", "1", "11", 8},
{"2020-01-02", "1", "11", 15},
{"2020-01-01", "2", "20", 5},
{"2020-01-02", "2", "20", 9},
{"2020-01-01", "2", "21", 13},
{"2020-01-02", "2", "21", 12}
},
{"day", "cat", "subcat", "amount"}
),
t1 = Table.TransformColumnTypes(t0, {{"amount", Int64.Type}})
in
t1
I can make the page start the chart showing the line for each category, which is what I want, by choosing the category as the legend
Now I want that when I click on the category line in the matrix the chart dynamicaly shows the lines for the subcategories of that category. Is it possible or is there another approach leading to the same result?
I'm not sure if it's possible to do drill down within the visual like that but you can make it work if you have filtering from a slicer or another visual.
First, create a new independent table to use on the x-axis that has both cat and subcat:
CatSubcat = UNION ( VALUES ( t1[cat] ), VALUES ( t1[subcat] ) )
Then we need a corresponding measure to go with it that switches between cat and subcat:
Measure =
IF (
HASONEVALUE ( t1[cat] ),
CALCULATE ( SUM ( t1[amount] ), t1[subcat] IN VALUES ( CatSubcat[cat] ) ),
CALCULATE ( SUM ( t1[amount] ), t1[cat] IN VALUES ( CatSubcat[cat] ) )
)
If nothing is filtered, it should look like this:
If you filter using the matrix to the left (or via a slicer on t1[cat]), you get this:
For more than two levels, this related post may be of use.
I am making a filtering system in flutter by using two lists called mailList and filteredMailList. The first time mailList is populated, this code runs:
setState(() {
filteredMailList.clear();
filteredMailList = mailList;
});
When this has been done, it seems as though any changes that I make on mailList get replicated to filteredMailList even though I haven't executed those two lines again. For example:
//Assume that mailList = ["1", "2", "3"] and filteredMailList = []
filteredMailList = mailList
//I expect then mailList = ["1", "2", "3"] and filteredMailList = ["1", "2", "3"]
mailList.add("4")
//I expect then mailList = ["1", "2", "3", "4"] and filteredMailList = ["1", "2", "3"]
//However when this is run mailList = ["1", "2", "3", "4"] and filteredMailList = ["1", "2", "3", "4"]
Does this have something to do with the fact that I might not be giving both lists the same contents, but instead saying that they are referencing the same list?
Is there a way to make filteredMailList only contain the elements of mailList and not actually reference the exact same list, so each one can still be edited independently?
in your code by calling filteredMailList = mailList; you are actually removing your original filteredMailList List (you don't have any refrence to that list anymore) and changing it to the mailList. so both filteredMailList and mailList points to a single List in memory
you can create a clone list from mailList like :
filteredMailList = [...mailList]; // or filteredMailList = mailList.toList();
or keep your original refrence and copy all items from mailList
filteredMailList.clear();
filteredMailList.addAll(mailList);
I am using a relatively new version of Power BI for Report Server.
I have this simplified data:
ImaginaryData =
DATATABLE (
"Fruit", STRING,
"Colour", STRING,
"Amount", INTEGER,
{
{ "Apple", "Red", 10 },
{ "Apple", "Green", 5 },
{ "Apple", "Blue", 17 },
{ "Pear", "Red", 100 },
{ "Pear", "Green", 65 },
{ "Pear", "Blue", 5 },
{ "Orange", "Red", 12 },
{ "Orange", "Green", 8 },
{ "Orange", "Blue", 38 }
} )
I then create a Matrix of the data:
I want to order this Matrix by amounts in the Blue column i.e. the Fruit Orange should be at the top of the list.
With a Table visual I hover over a column header and can then order by that column but that functionality does not appear for a Matrix.
How do I workaround this issue? [using a Table is not a solution]
You need to add a sortcolumn to your table, that holds the sum of the blue amounts for that particular fruit. Like this.
You cannot do this in DAX (calculated column), because then you can't sort [Fruit] by [Sort], because [Sort] is allready indirectly sorted by [Fruit].
So you need to use the Query-editor. I recreated your table in an excel-workbook to import it. Then I used the following M script
let
SortColour = "Blue",
Source = Excel.Workbook(File.Contents("C:\Users\XXXXX\Documents\ImaginaryData.xlsx"), null, true),
ImaginaryData_Table = Source{[Item="ImaginaryData",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(ImaginaryData_Table,{{"Fruit", type text}, {"Colour", type text}, {"Amount", Int64.Type}}),
JoinTable = Table.SelectRows(Table.Group(#"Changed Type", {"Fruit", "Colour"}, {{"Count", each List.Sum([Amount]), Int64.Type}}), each ([Colour] = SortColour)),
#"Merged Queries" = Table.NestedJoin(#"Changed Type",{"Fruit"},JoinTable,{"Fruit"},"SortTable",JoinKind.LeftOuter),
#"Expanded SortTable" = Table.ExpandTableColumn(#"Merged Queries", "SortTable", {"Count"}, {"Sort"})
in
#"Expanded SortTable"
After loading this query, you can sort [Fruit] by [Sort] in the Data view (Sort by Column on the Modeling tab). Then recreate the matrix visual and sort the Fruit Column descending by clicking the triangle in the visual.
When you add row { Pear / Blue / 50 } to the table in excel and refresh in PowerBI, the matrix changes to this:
I'm expecting this code to print spade:A spade:2 and so on until heart:K.
But it only does heart:A to heart:K.
How should I do it?
symbols = ["spade", "clover", "diamond", "heart"]
numbers = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
cards = {}
for num in numbers:
for symbol in symbols:
cards[num] = symbol
print cards
Use your itertools toolbox
import itertools
symbols = ["spade", "clover", "diamond", "heart"]
numbers = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
combinations = itertools.product(symbols, numbers)
cards = ["{}:{}".format(suit, rank) for suit,rank in combinations]
This will give you the list:
['spade:A',
'spade:2',
'spade:3',
'spade:4',
'spade:5',
'spade:6',
'spade:7',
'spade:8',
'spade:9',
'spade:10',
'spade:J',
'spade:Q',
'spade:K',
'clover:A',
'clover:2',
'clover:3',
'clover:4',
'clover:5',
'clover:6',
'clover:7',
'clover:8',
'clover:9',
'clover:10',
'clover:J',
'clover:Q',
'clover:K',
'diamond:A',
'diamond:2',
'diamond:3',
'diamond:4',
'diamond:5',
'diamond:6',
'diamond:7',
'diamond:8',
'diamond:9',
'diamond:10',
'diamond:J',
'diamond:Q',
'diamond:K',
'heart:A',
'heart:2',
'heart:3',
'heart:4',
'heart:5',
'heart:6',
'heart:7',
'heart:8',
'heart:9',
'heart:10',
'heart:J',
'heart:Q',
'heart:K']
The problem is that you are not iterating the right way and thus you are not appending in the list. The right way to do it is
symbols = ["spade", "clover", "diamond", "heart"]
numbers = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
cards = []
for j in range(len(symbols)):
for i in range(len(numbers)):
cards.append(str(symbols[j]+':'+str(numbers[i])))
print cards
with output:
['spade:A', 'spade:2', 'spade:3', 'spade:4', 'spade:5', 'spade:6', 'spade:7', 'spade:8',
'spade:9', 'spade:10', 'spade:J', 'spade:Q', 'spade:K', 'clover:A', 'clover:2',
'clover:3', 'clover:4', 'clover:5', 'clover:6', 'clover:7', 'clover:8', 'clover:9',
'clover:10', 'clover:J', 'clover:Q', 'clover:K', 'diamond:A', 'diamond:2', 'diamond:3',
'diamond:4', 'diamond:5', 'diamond:6', 'diamond:7', 'diamond:8', 'diamond:9', 'diamond:10',
'diamond:J', 'diamond:Q', 'diamond:K', 'heart:A', 'heart:2', 'heart:3', 'heart:4',
'heart:5', 'heart:6', 'heart:7', 'heart:8', 'heart:9', 'heart:10', 'heart:J', 'heart:Q', 'heart:K']
Made with Ipython Notebook in python 2.7
Hope it helps.
You are iterating the symbols just fine but when you are going over the numbers in the second loop, you are actually replacing the values set by the previous loop hence you only have values from the last loop left and everything is replaced. This means cards["A"] value is set 4 times in the loop and the last for the "heart" is retained. The same thing is happening for all the other indexes.