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.
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman2 -
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.7K Product Ideas
- 1.7K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 293 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.8K Transform
- 96 SQL DataFlows
- 607 Datasets
- 2.1K Magic ETL
- 3.8K Visualize
- 2.4K Charting
- 705 Beast Mode
- 49 App Studio
- 39 Variables
- 667 Automate
- 170 Apps
- 446 APIs & Domo Developer
- 44 Workflows
- 7 DomoAI
- 33 Predict
- 13 Jupyter Workspaces
- 20 R & Python Tiles
- 391 Distribute
- 111 Domo Everywhere
- 274 Scheduled Reports
- 6 Software Integrations
- 115 Manage
- 112 Governance & Security
- Domo Community Gallery
- 31 Product Releases
- 9 Domo University
- Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 103 Community Announcements
- 4.8K Archive