Issue with null data
I am using the below beast modes calculations for a chart. where I am trying to find the no of records received today and yesterday. Data appends itself in the dataset date wise.
Eg: if yesterday 1 record received, today 2 records received. dataset will show 3 count for today.
Beastmode:
today:
case WHEN SUM(CASE WHEN event_date
= CURDATE() then records
END) - SUM(CASE WHEN event_date
= CURDATE() -1 then records
END) > 0
THEN SUM(CASE WHEN event_date
= CURDATE() then records
END) - SUM(CASE WHEN event_date
= CURDATE() -1 then records
END)
else 0 END
Yesterday:
case WHEN SUM(CASE WHEN event_date
= CURDATE() -1 then records
END) - SUM(CASE WHEN event_date
= CURDATE() -2 then records
END) > 0
THEN SUM(CASE WHEN event_date
= CURDATE() -1 then records
END) - SUM(CASE WHEN event_date
= CURDATE() -2 then records
END)
else 0 END
But in the table it is not populating correct value.
Best Answer
-
@Dheeraj_1996 If you only want to keep positive variances across multiple rows, then you'll need to restructure your data to include a column to include the previous days'
records
value. You can do this by using the LAG function in the MagicETL Rank & Window tile. Once you have added this column you can use a single aggregated case statement in your card like this:Today
sum(case when `event_date` = CURDATE() and `records` >= `previous_day_records` then `records` - `previous_day_records` else 0 end)
Yesterday
sum(case when `event_date` = CURDATE() - 1 and `records` >= `previous_day_records` then `records` - `previous_day_records` else 0 end)
0
Answers
-
The summing is throwing things off.
This will get you the intended result:
Today
count(case when `event_date` = current_date() then `records` end)
Yesterday
count(case when `event_date` = date_sub(current_date(), interval 1 day) then `records` end)
0 -
No this does not help, My dataset has multiple error codes for every day and aggregated records in it.
0 -
@Dheeraj_1996 You should be able to use @nmizzell's logic if you change the aggregation from COUNT to SUM
0 -
No it isn't giving the desired result. it is populating all the records.. but i need the difference from today to yesterday. In my beastmode I am getting the correct figures, but the subtotal is incorrect. the subtotal when -ve is also converting to 0.
0 -
@Dheeraj_1996 I see. Based on the example in your original post it sounded like you wanted to simply add them. In that case, the issue has to do with the ELSE 0 your outer case statements. I'd suggest changing your formulas to be structured like this:
Today:
SUM(CASE WHEN event_date = CURDATE() then records else 0 END) - SUM(CASE WHEN event_date = CURDATE() - 1 then records else 0 END)
Yesterday:
SUM(CASE WHEN event_date = CURDATE() - 1 then records else 0 END) - SUM(CASE WHEN event_date = CURDATE() - 2 then records else 0 END)
0 -
yes, I am doing this. but this fetches -ve value when records decrease. I only want +ve entries so I am converting things to 0 when -ve. but then it is giving issue
0 -
@Dheeraj_1996 If you only want to keep positive variances across multiple rows, then you'll need to restructure your data to include a column to include the previous days'
records
value. You can do this by using the LAG function in the MagicETL Rank & Window tile. Once you have added this column you can use a single aggregated case statement in your card like this:Today
sum(case when `event_date` = CURDATE() and `records` >= `previous_day_records` then `records` - `previous_day_records` else 0 end)
Yesterday
sum(case when `event_date` = CURDATE() - 1 and `records` >= `previous_day_records` then `records` - `previous_day_records` else 0 end)
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