Finding the last non-zero value in each column
I've got a DataSet with several columsn. Each column stores a single statistic:
TotalItems
NewItems
RepairItems
There are many rows, each of which has each column along with data, location name and other values of interest.
Here's the question: Sometimes rows have 0's that indicate 'no change'. What we're after is a chart that uses the last non-zero value in each column as the data for the plot. There's a timestamp in each row, so it's not hard to figure the order and what "last" might mean.
The problem here is that we're not going to find the right value for each column in the same row. So, I can just get the last row. Also, the value won't always be the MAX or else I could use that.
Is there a clever beast mode that might help out here, or do I need to rework my DataSet?
Thanks!
Best Answer
-
Yes, you'll need a SQL transform.
Something like:
SELECT * FROM tableORDER BY `Timestamp`
LIMIT 1
That will give you the most recent row of data
1
Answers
-
Possibly as a related quesiton, how do you select only the latest (by timestamp) row for a plot? So, if we've got 5,000 rows, only the last 1 is used for the chart.
Thanks again!
1 -
So if I understand you correctly, you're wanting to return the last "Non-zero" value found in each column based on the timestamp you have in a column.
If I were going to tackle this one in my own environment, I would do it in a SQL transform.
The pseudocode would look something like this:
SELECT `Identifier`,
(SELECT `Col1` FROM table WHERE `Col1` <> '0' ORDER BY `Timestamp` DESC LIMIT 1) AS 'Col1'
FROM table
Obviously, continue repeating the subquery for each column you're trying to find the last non-zero value for.
Then you can use the result of that transform as your base for your chart.
Hope this helps. Let me know if you have any questions.
Sincerely,
ValiantSpur
**Please mark "Accept as Solution" if this post solves your problem
**Say "Thanks" by clicking the "heart" in the post that helped you.2 -
You could start by filtering out the zero values and then sort the data by your timestamp field in descending order. That should give you your most recent data first.
If you could provide a bit of your data, I may be able to give a more in depth answer.
2 -
Great answer, thanks for the reply! Given that, I'd probably be better off biulding a one-row data set to push into Domo. The code will be similar to what you propose, but we're currently aiming to keep most of our data prep logic outside of Domo. I know, that's not the Domo way...but it's working well for us so far. Staying open minded though...
0 -
As it turns out, this is what I actually need to do today. Just find the most recent row. Our data set is mostly used to find _trends_, but sometimes we want to find _status_. The current/latest day gives us a snapshot of the current status. I don't see anything like a TOP or LAST function in the Beast Mode reference, or any kind of ORDER BY. Is this (finding the most recent row) another case for a SQL Transform?1
-
Yes, you'll need a SQL transform.
Something like:
SELECT * FROM tableORDER BY `Timestamp`
LIMIT 1
That will give you the most recent row of data
1 -
Thanks! I havn't tried SQL Transforms, so here's a good excuse to try them out. That will put me in a better place to decide if we should prep an extra DataSet on the outside or do it in Domo.
Thanks again for all of the help!
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 753 Beast Mode
- 61 App Studio
- 41 Variables
- 692 Automate
- 177 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive