CAlculated Average to include in my datasource
Hi All, I need help since I am not familiar with sql, but I need to a column with the calculated average for a particular product which does not have averages available in my datasource.
This is a small sample of my data:
As you can see the AUM product does not have an average balance in the source system hence it has to be a calculated field where the calculation is based on the spots balances of that particular account and product from prior month and current month / 2.
Thanks in advance for your help! have a great day.
Comments
-
yikes... this is ... not the ideal way to structure your data ... but we can make it work.
Goal: identify the record that = the first day of the month and the last day of the month then caculate the average between the two.
If it were me, I would recommend adding these collumns to a date dimension and then joining the date dimension to your dataset, so that you can recycle your code everywhere, but most people take the lazy solution and just build the logic into the card...
https://stackoverflow.com/questions/3960049/create-date-from-day-month-year-fields-in-mysql
sum(
CASE
-- is it the start of the month??
WHEN 'date' = DATE_SUB(date, INTERVAL DAYOFMONTH(date)-1 DAY) then 'Amount'
-- is it the end of the month??
WHEN 'date' = LAST_DAY(date) then 'Amount'
) / 2Jae Wilson
Check out my 🎥 Domo Training YouTube Channel 👨💻
**Say "Thanks" by clicking the ❤️ in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"0 -
Thank you!
What I had in mind was not to add this calculation as a beast mode but to add the column in my current database, since once it is done I have to append it to the databases from other countries. That is what I thought about addressing it via sql.
I think I got lost when you say identify the first day of the month, since my data only has the last day of the reporting month.
0 -
oh ... well that makes it easier i guess. sorry i'm half looking at this at 9PM ?
You can do this with a LAG function in a beast mode.
Contact your CSM to get windowed functions enabled on your instance.
Jae Wilson
Check out my 🎥 Domo Training YouTube Channel 👨💻
**Say "Thanks" by clicking the ❤️ in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"0 -
You can actually get this field populated pretty easily using Magic ETL. Here's a picture of what your ETL would generally look like:
Here's a breakdown of the steps in the ETL
1. Split your input dataset into to two datasets by using the filter tiles. Filter one to Product equals AUM. Filter the other one to not equal to AUM.
2. Not pictured above, but you need to add a select columns tile on your AUM filtered data set and add all columns except for the average balance column.
3. Add a Rank & Window tile on the AUM filtered data. Use the AVG function and sort by date ascending and use the preceding and following values of 1 and 1. This will create a rolling average based off the month and the prior month. Name the column average balance (the same name that is in your main dataset).
4. Append the data back together using shared columns.
5. Add and name your output dataset.
This should do it for you.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.2 -
Thanks Mark! I added a partition to include the account and it work perfectly. Quick question, do you have any tip to overcome the months with no data.
Ie: I have cases that the account haven't had any balance for more that 1 month hence is is not being fed into the datasource. The average then it is being calculated since the last month that particular account had balance.
0 -
Yes, you can overcome this with a few additional steps. Here is what you would want to do:
1. Add a 3rd connection from the input to dataset to a Select Columns tile and just select the month column.
2. Connect a Remove Duplicates tile to that tile and choose Month to get a distinct list of months from your dataset.
3. Add a join tile to connect the Remove Duplicates tile with the Filter to AUM tile and do a Left Join with Remove Duplicates on the left and join on Month.
4. Add a Value Mapper tile and replace nulls with 0 on the spot balance column.
5. Connect to the Rank & Window tile you already configured.
It should look something like this:
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.0 -
@MarkSnodgrass what if you have NO data for any account in August? Do you want to skip the month of August from your percentage calc?
Jae Wilson
Check out my 🎥 Domo Training YouTube Channel 👨💻
**Say "Thanks" by clicking the ❤️ in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"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