Jad Jabareen
12/05/2024, 6:22 PMSELECT SUM(
CASE
WHEN #Q124
{label/As_Of_Date.day} >= "2024-01-01"
AND {label/As_Of_Date.day} <= "2024-03-31"
AND THIS(DAY) >= "2024-01-01"
AND THIS(DAY) <= "2024-03-31"
THEN {fact/balanace_sheet_balance},
WHEN #Q224
{label/As_Of_Date.day} >= "2024-04-01"
AND {label/As_Of_Date.day} <= "2024-06-30"
AND THIS(DAY) >= "2024-04-01"
AND THIS(DAY) <= "2024-06-30"
THEN {fact/balanace_sheet_balance},
WHEN #Q324
{label/As_Of_Date.day} >= "2024-07-01"
AND {label/As_Of_Date.day} <= "2024-09-30"
AND THIS(DAY) >= "2024-07-01"
AND THIS(DAY) <= "2024-09-30"
THEN {fact/balanace_sheet_balance},
WHEN #Q424
{label/As_Of_Date.day} >= "2024-10-01"
AND {label/As_Of_Date.day} <= "2024-12-31"
AND THIS(DAY) >= "2024-10-01"
AND THIS(DAY) <= "2024-12-31"
THEN {fact/balanace_sheet_balance}
ELSE 0
END
)
Jad Jabareen
12/05/2024, 6:49 PM{label/As_Of_Date.day} >= "2024-01-01"
AND {label/As_Of_Date.day} <= "2024-03-31"
the code seems to return values other than 0, so I suspect that this is part of the issue. I'd love some help to fix it. I checked the documentation for comparison operators and referring to dates.Mauricio Cabezas
12/05/2024, 7:43 PMJad Jabareen
12/05/2024, 7:45 PMJad Jabareen
12/05/2024, 7:49 PMMauricio Cabezas
12/05/2024, 8:00 PMSELECT sum({fact/TotalAmount}) WHERE {label/SaleDate.quarterOfYear} = THIS(QUARTEROFYEAR)
In your case must be something like:
SELECT sum({fact/balanace_sheet_balance}) WHERE {label/As_Of_Date.quarterOfYear} = THIS(QUARTEROFYEAR)
Can you test it, please?Mauricio Cabezas
12/05/2024, 8:05 PMJad Jabareen
12/05/2024, 8:14 PMMauricio Cabezas
12/05/2024, 8:42 PMJad Jabareen
12/05/2024, 8:57 PMJakub Sterba
12/05/2024, 11:40 PMSELECT sum({fact/balanace_sheet_balance}) WHERE {label/As_Of_Date.quarter} = THIS(QUARTER)
should display summary value for the current quarter the same as if the filter is applied for the metric in the UI.Jad Jabareen
12/06/2024, 6:50 PMJakub Sterba
12/06/2024, 7:33 PMIF {label/As_Of_Date.day}=THIS(Quarter)
is used in a metric which is displayed for example as headline, it will work the way that it will compute both variants THEN and ELSE and then it will have to evaluate condition for the result to chose which of the two results to use. You would need to use probably BY rules and more complex metric to get it working this way. E.g.
SELECT SUM(
SELECT IF .... THEN SUM(...) ELSE ( SELECT SUM(...) FOR PREVIOUS(...) ) BY {label/As_Of_Date.day}
)
the by rule will tell to calculate SUM in the THEN clause for each day and also SUM for previous period by day and then based on condition for each day select which of the two computed values will be used for final aggregation using SUM.
So if I understand right SUM({fact/balance_sheet_balance})
broken down by {label/As_Of_Date.day}
provides snapshot value of balance for each day.
Maybe you can use alternative method how to compute it.
SELECT LAST_VALUE(SUM({fact/balance_sheet_balance}))
ORDER BY {label/As_Of_Date.day}
BY {label/As_Of_Date.quarter}
WHERE {label/As_Of_Date.quarter} = PREVIOUS(QUARTER)
should compute last day snapshot of each quarter and filter this value for the last quarter
SELECT
( SELECT SUM({fact/balance_sheet_balance}) WHERE {label/As_Of_Date.day}=THIS(DAY))
-
( SELECT LAST_VALUE(SUM({fact/balance_sheet_balance}))
ORDER BY {label/As_Of_Date.day}
BY {label/As_Of_Date.quarter}
WHERE {label/As_Of_Date.quarter} = PREVIOUS(QUARTER)
)
should return difference between todays snapshot and last snapshot of last quarterJakub Sterba
12/06/2024, 7:57 PMJad Jabareen
12/06/2024, 8:25 PMJad Jabareen
12/06/2024, 10:19 PMJakub Sterba
12/07/2024, 9:47 PM