Google Chart API table format for charts - google-visualization

Hopefully this makes sense. I will probably just keep mulling this over, until i figure it. I have a table, that is formatted in such as way, that a specific date may have more than one record assigned. Each record is a plant, so the structure of that table looks like the pinkish table in the image below. However when using the Google chart API the data needs to be in the format in the blue table for a line chart. Which I have working.
I am looking to create a graph in the Google chart api similar to the excel graph, using the pink table. Where at one date e.g. 01/02/2003 there are three species recorded A,B,C with values 1,2,3. I thought possibly using a scatter but that didn't work either.
What ties these together is the CenterID all these records belong to XXX CenterID. Each record with its species has an SheetID that grouped them together for example SheetID = 23, all those species were recorded on the same date.
Looking for suggestions, whether google chart API or php amendments. My PHP is below (I will switch to json_encode eventually).
$sql = "SELECT * FROM userrecords";
$stmt = $conn->prepare($sql);
$stmt->execute();
$data = $stmt->fetchAll();
foreach ($data as $row)
{
$dateArray = explode('-', $row['eventdate']);
$year = $dateArray[0];
$month= $dateArray[1] - 1;
$day= $dateArray[2];
$dataArray[] = "[new Date ($year, $month, $day), {$row['scientificname']}, {$row['category_of_taxom']}]";

To get that chart, where the dates are the series instead of the axis values, you need to change the way you are pulling your data. Assuming your database is structured like the pink table, you need to pivot the data on the date column instead of the species column to create a structure like this:
| Species | 01/02/2003 | 01/03/2003 | 01/04/2003 |
|---------|------------|------------|------------|
| A | 1 | 2 | 3 |
| B | 3 | 1 | 4 |
| C | 1 | 3 | 5 |

Related

Creating a Music Podium top 5 - like visualization in Power BI from a table

I am met with the challenge of creating a music visualization in Power BI, I have already created the DAX code to come up with a table that will rank the postion of the top 5 songs of the week including the name of the artist and if the song is trending (up) , is going down positions (down) or is maintaning its positions (hold)
the output table looks like this:
| song | position | artist | trend | image_for_viz |
|:---------------:|:--------:|:------------:|:-----:|:-------------:|
| Happy Vibes | 1 | Alex Gibbs | up | x.jpg |
| Melodies | 2 | Amanda S. | hold | y.jpg |
| Only You | 3 | B,Y.I | up | z.jpg |
| 2nite ft. Y-R-U | 4 | Lory & Y-R-U | hold | i.jpg |
| Green Grass | 5 | Jake Hill | down | m.jpg |
you will notice I also have a column for the .jpg image I need to create something like this:
I'd like to create a table so transparent and in such a way that I can upload the image that I need to create the topchart top5 viz above I have gone through so many power bi libraries and i cant seem to find my desired viz or something close to it, from the bottom of my heart thank you so much if you know how to do this I will be forever thankful, also please know that I will be super attentive to upvote and select the best answer thank you so much guys
You have two options to solve this:
Use Deneb custom visual. This isn't difficult but is a little involved if you're not familiar with Vega.
Use a combination of native visuals. As you only have 5 datapoints which never increase or decrease, you can layout 5 images for your numbers. Then next to each image, insert a text box with a measure for the specific ranked song and artist. For your up/down icons, you again insert shapes with arrows and circles. You insert both an up and down icon on every line and control the opacity through DAX. i.e. everything is transparent unless your measure states it should be up or down.
Edit: How To.
Insert an image
Create a measure for song as follows:
1song = CALCULATE( MIN('Table'[song]), 'Table'[position] = 1)
Create a measure for artist as follows:
1artist = CALCULATE( MIN('Table'[artist]), 'Table'[position] = 1)
Insert a text box next to your number and inside the text box include the two new measures.
Insert two arrows and turn their borders off, making one green and one red.
Create a measure as follows:
1green = IF( CALCULATE( MIN('Table'[trend]), 'Table'[position] = 1) =="up","green", "#00000000" )
And another
1red = IF( CALCULATE( MIN('Table'[trend]), 'Table'[position] = 1) =="down","red", "#00000000" )
Highlight green arrow and in formatting pane, select Fill and the fx button. Complete as follows:
9 Do same for red arrow and measure
10 That's it. Repeat 5 more times for your other positions.
Final result:

power automate desktop - convert list into data table

I read some text from a pdf into Power automate desktop. It is in the form of a list like
0 | 123 Testing Company 23.00
1 | Generation Z Co 555.11
2 | Tea Company 1,234.99
I need to separate the list into columns where the number at the end of the element is in its own column like
0 | 123 Testing Company | 23.00
1 | Generation Z Co | 555.11
2 | Tea Company | 1,234.99
Is there a way to do this? I've tried to extract tables from PDF instead but this method does not return the right data, because it seems PAD doesn't recognize it as a table.
Is there a way to convert a list into a data table?
The only way seems to be to For Loop the List,
Parse Text each of the columns
and insert them each as a row to the Data table.
i feel like there should be a quicker way to do this.

Add condition to an existing column

I have the following columns in my dataset:
_____________________________________________________________________________________
| ... |Start Date| Start Time | End Date | End Time | Production Start Date | ... |
|_____|__________|____________|____________|____________|_______________________|_____|
| ... | 01022020 | 180000 | 02022020 | 190000 | 01022020 | ... |
| | | | | | | |
Sometimes the Start Date + Start Time etc. values are blank but the Production Start Date values are always populated.
When the Start Date is empty (NULL), for example, I want my dataset (or ideally, graph) to read the Production Start Date.
How can I achieve this in Power BI?
I know I can make a conditional column, then within that, determine which column to read data from but is there any way to add a condition to the existing Start Date column? I couldn't see such an option in the context menu or subsequent ribbon options.
Is my only option to create a custom conditional column instead?
As #Andrey Nikolov mentioned in the comments, the only ways you can achieve this is to:
1 Create a calculated DAX column.
2 Create a custom column in query mode (M).
3 Edit the original source table.
doug

Split data into categories in the same row in Power BI

I have a table that contains multiple columns with their named having either the suffix _EXPECTED or _ACTUAL. For example, I'm looking at my sold items from my SoldItems Table and I have the following columns: APPLES_EXPECTED, BANANAS_EXPECTED, KIWIS_EXPECTED, APPLES_ACTUAL, BANANAS_ACTUAL, KIWIS_ACTUAL (The Identifier of the table is the date, so we have results per date). I want to show that data in a table form, something like this (for a selected date in filters:
+------------+----------+--------+
| Sold items | Expected | Actual |
+------------+----------+--------+
| Apples | 10 | 15 |
| Bananas | 8 | 5 |
| Kiwis | 2 | 1 |
+------------+----------+--------+
How can I manage something like this in Power BI ? I tried playing with the matrix/table visualization, however, I can't figure out a way to merge all the expected and actual columns together.
It looks like the easiest option for you would be to mould the data a bit differently using Power query. You can UNPIVOT your data so that all the expected and actual values become rows instead of columns. For example take the following sample:
Date Apples_Expected Apples_Actual
1/1/2019 1 2
Once you unpivot this it will become:
Date Fruit Count
1/1/2019 Apples_Expected 1
1/1/2019 Apples_Actual 2
Once you unpivot, it should be fairly straightforward to get the view you are looking for. The following link should walk you through the steps to unpivot:
https://support.office.com/en-us/article/unpivot-columns-power-query-0f7bad4b-9ea1-49c1-9d95-f588221c7098
Hope this helps.

PowerBI Count all Rows With Value In Group

This seems like one of the use cases for groups, but maybe I'm understanding them wrong.
I have a table that shows a count of all rows like this:
User | Completed Tasks
Bob | 2
Jim | 1
Pete | 1
The table it comes from looks like this:
User | Type
Bob | A
Bob | B
Jim | A
Pete | C
This is very simplified - in reality there are about 80 different types - I'm hoping to get 5 of them in a group called Secondary and the rest in a group called Primary
For the example, say I want A and B to be considered "primary" and C to be secondary.
The new table would look like this:
User | Completed Tasks | Primary | Secondary
Bob | 2 | 2 | 0
Jim | 1 | 1 | 0
Pete | 1 | 0 | 1
I tried creating a group of Type with 5 called Secondary and the rest called Primary, but I was having trouble figuring it out.
I just want a Count of types for that particular group based on the filtered values and everything.
Is there an easy way to do this or do I need to create a measure/calculated column?
I ended up solving this by creating two calculated columns.
The Dax for the primary would be a 1 for each row not in the Secondary list:
PrimaryCount = IF(table[Type] in {"C","D","E","F","G"},0,1)
The Dax for the secondary would be a 1 for each row IN the Secondary list:
SecondaryCount = IF(table[Type] in {"C","D","E","F","G"},1,0)
Then, just add those to your table values and make sure Sum is selected (the default).
I figured using groups would be easier, but I suppose this is simple enough and seems to work.
Another way to approach this is to create a calculated column for Group
Group = IF(table[Type] IN {"A","B"}, "Primary", "Secondary")
You can then use the Group as the columns on a matrix and count the Type column.
Note that this approach scales better if you want to break into a lot more groups. You'd likely want to use a SWITCH in that case like this:
Group =
SWITCH(TRUE(),
Table1[Type] IN {"A","B"}, "Primary",
Table1[Type] IN {"C"}, "Secondary",
Table1[Type] IN {"D", "E", "F"}, "Tertiary",
"Other"
)