通过季度的百分比

Percentage of quarter passed

我正在尝试创建一个计算字段来显示到目前为止该季度的百分比。这是我想出的:

DATEDIFF('day',DATETRUNC('quarter',[Max Date in quarter]),[Max Date in quarter]) //days past in the quarter so far

/

//total days in quarter
IF (DATEPART('quarter', TODAY()) = 1) THEN
    DATEDIFF('day', #2019-01-01#, #2019-03-31#)
ELSEIF (DATEPART('quarter', TODAY()) = 2) THEN
    DATEDIFF('day', #2019-04-01#, #2019-06-30#)
ELSEIF (DATEPART('quarter', TODAY()) = 3) THEN
    DATEDIFF('day', #2019-07-01#, #2019-09-30#)
ELSEIF (DATEPART('quarter', TODAY()) = 4) THEN
    DATEDIFF('day', #2019-10-01#, #2019-12-31#)
END

[Max Date in Quarter] 看起来像:

{ FIXED YEAR([Yyyy Mm Dd]), DATETRUNC('quarter',[Yyyy Mm Dd]): MAX([Yyyy Mm Dd])}

但是,它似乎没有按预期工作。对于 Q1 2019,我得到 97.8%,对于 Q2 2019,我得到 98.9%。我希望两者都是 100%。

此外,有没有一种方法可以动态更新年份,这样到 2020 年时,我就不会被赶上并需要在此处手动更改日期?

我使用以下方法获得了正确的百分比:

//days past in the quarter so far
IF (DATEPART('quarter', [Max Date in quarter]) = 1) THEN
    DATEDIFF('day', #2019-01-01#, today())
ELSEIF (DATEPART('quarter', [Max Date in quarter]) = 2) THEN
    DATEDIFF('day', #2019-04-01#, today())
ELSEIF (DATEPART('quarter', [Max Date in quarter]) = 3) THEN
    DATEDIFF('day', #2019-07-01#, today())
ELSEIF (DATEPART('quarter', [Max Date in quarter]) = 4) THEN
    DATEDIFF('day', #2019-10-01#, today())
END

/

//total days in quarter
IF (DATEPART('quarter', [Max Date in quarter]) = 1) THEN
    DATEDIFF('day', #2019-01-01#, [Max Date in quarter])
ELSEIF (DATEPART('quarter', [Max Date in quarter]) = 2) THEN
    DATEDIFF('day', #2019-04-01#, [Max Date in quarter])
ELSEIF (DATEPART('quarter', [Max Date in quarter]) = 3) THEN
    DATEDIFF('day', #2019-07-01#, [Max Date in quarter])
ELSEIF (DATEPART('quarter', [Max Date in quarter]) = 4) THEN
    DATEDIFF('day', #2019-10-01#, [Max Date in quarter])
END