aggregate function with case when condition in calculated field

Hi, have a question for how aggregate function with case when condition in calculated field.
- domo dataset follow attached schema/data,
- then create a Single Value card from this dataset,
- then I created a filter Team=team1
I want to archive:
have a calculated field , use total of col Old_Col before 2023-04-01( should be 2) , or use col New_Col after 2023-04-01( should be 2) , get the sum of this, to divide Count(Distinct(`ID`)) ( should be 7) , to get a rate, as 4/7 =0.57 .
Here is how I write the calculated field:
Name: Failed_Rate
Calculation: (CASE WHEN ReleasedDate
>= '2023-04-01T00:00:00' THEN SUM(New_Col
)
WHEN ReleasedDate
< '2023-04-01T00:00:00' THEN SUM(Old_Col
)
END)/Count(DISTINCT(ID
))
Name: Total_Failed
Calculation: (CASE WHEN ReleasedDate
>= '2023-04-01T00:00:00' THEN SUM(New_Col
)
WHEN ReleasedDate
< '2023-04-01T00:00:00' THEN SUM(Old_Col
)
END)
But it displays something odd:
1. why in Data Table the value is 0.29, but Card display 2.4?
2. Total_Failed should be 4, not 2
I think somehow my calculated field as Failed_Rate not correct, but I am not sure how to fix it.
Thank you for any help
Best Answer
-
Good Morning Liuli,
Try this…
SUM(CASE WHEN
ReleasedDate
>= '2023-04-01T00:00:00' THENNew_Col
WHENReleasedDate
< '2023-04-01T00:00:00' THENOld_Col
END)The reason your original calculation did not work is because a CASE statement is granular and a SUM statement is aggregate. Using aggregate statements inside granular statements is very unpredictable.
Hope this helps!
Samantha
Brought to you by Arigato Analytics.
2
Answers
-
Good Morning Liuli,
Try this…
SUM(CASE WHEN
ReleasedDate
>= '2023-04-01T00:00:00' THENNew_Col
WHENReleasedDate
< '2023-04-01T00:00:00' THENOld_Col
END)The reason your original calculation did not work is because a CASE statement is granular and a SUM statement is aggregate. Using aggregate statements inside granular statements is very unpredictable.
Hope this helps!
Samantha
Brought to you by Arigato Analytics.
2 -
@Sam_Arigato , you solution works!
it totally saved my day and thank you so much for you quick response.0
Categories
- All Categories
- 1.1K Product Ideas
- 1.1K Ideas Exchange
- 1.2K Connect
- 970 Connectors
- 259 Workbench
- Cloud Amplifier
- 1 Federated
- 2.4K Transform
- 76 SQL DataFlows
- 502 Datasets
- 1.8K Magic ETL
- 2.7K Visualize
- 2.2K Charting
- 379 Beast Mode
- 21 Variables
- 487 Automate
- 104 Apps
- 379 APIs & Domo Developer
- 6 Workflows
- 22 Predict
- 6 Jupyter Workspaces
- 16 R & Python Tiles
- 319 Distribute
- 67 Domo Everywhere
- 252 Scheduled Reports
- 59 Manage
- 59 Governance & Security
- 1 Product Release Questions
- 5K Community Forums
- 37 Getting Started
- 23 Community Member Introductions
- 64 Community Announcements
- 4.8K Archive