LAG / LEAD function misses the last iteration
Hi experts!
I'm using the lead / lag function in beast mode to find out the last row from each group of index rows simply by comparing the value of primary key of next/previous. It works accurately except it misses the last / first group (last when using lead and first when using lag).
Here's my beast mode code:
And, here's my data table and result of the calculated field...
If you see it correctly punches '1' for the group Canada, but misses for US. If I use the lag function, it punches value for US but misses for Canada.
One way I could think of is to punch '1' by default for the last row, but I couldn't found the way to use WHEN and identify the last row - if you could help me with that, it would be great.
---------------------------------------
Currently, I'm using a sloppy workaround of using both 😋 (see below) - it works but I want to do it much cleaner way.
Current workaround:
Best Answer
-
Hi - rank() and count() did the work!
0
Answers
-
Also, if there's only one group, then lead/lag doesn't work at all!!
So, in that case, I just want to punch '1' for the last row. Is there a way to use CASE..WHEN..END to punch a value for the last row? something like...
CASE
WHEN CURRENT_ROW() = LAST_ROW() THEN 1
END
==================================================================
Using MAX & FIXED BY works in general, see below...
... but when I apply filter on that calculated field to show only latest row, it picks the first row with blank version irrespectively. Ideally it should have filtered the row with version "2022-11-08-0014", however, it picks the row with blank version irrespectively. I even tried to sort the versions with descending order but doesn't work...
0 -
Hi - rank() and count() did the work!
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 297 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 614 Datasets
- 2.2K Magic ETL
- 3.8K Visualize
- 2.5K Charting
- 729 Beast Mode
- 53 App Studio
- 40 Variables
- 678 Automate
- 173 Apps
- 451 APIs & Domo Developer
- 46 Workflows
- 8 DomoAI
- 34 Predict
- 14 Jupyter Workspaces
- 20 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 121 Manage
- 118 Governance & Security
- Domo Community Gallery
- 32 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive