美好的一天,
我遇到的问题是,我有一组数据来自评估,而这些评估并非按月为所有商店进行,但我想用于评估的是最新的数据。 数据的示例如下
Shop Date Total
A 15/01/18 85
A 15/03/18 78
B 15/01/18 73
B 15/02/18 69
C 15/03/18 92
例如在商店A和C中显示3月的结果没有问题,但是对于商店B我无法显示信息,因为如果我按月过滤我没有得到任何东西。
那么有可能获得最后一个可用值吗?
答案 0 :(得分:0)
这是一个非常复杂的问题,除非我遗漏了什么。使用LASTNONBLANK()
只能让您获得解决方案的一部分。
我从未见过有人发布过一种方法来解决你的情况,虽然我已经看到一些在某些方面相似的方法
Matt Allington:https://exceleratorbi.com.au/lastnonblank-explained/显示了当列末尾缺少数据时如何在小计区域中正确显示最后一个值。
Marco Russo:https://www.sqlbi.com/articles/semi-additive-measures-in-dax/具有指导性,但它会在日期表中用完日期之前保留最终余额。
我并不是说这个措施效率最高,但它应该达到你想要的目标:
Most Recent Balance =
-- The first day of the period in context (not just for which we have data)
VAR context_first_date = FIRSTDATE(data[Date].[Date])
-- The last day of the period in context (not just for which we have data)
VAR context_last_date = LASTDATE(data[Date].[Date])
-- See if there are any transactions after the beginning of this period
VAR transactions_before_end = CALCULATE(COUNTROWS(data), FILTER(ALL(data), data[Date] <= context_last_date))
-- See if there are any transactions before the end of this period
VAR transactions_after_beginning = CALCULATE(COUNTROWS(data), FILTER(ALL(data), data[Date] >= context_first_date))
-- Find the last date for which there was a transaction
VAR transaction_last_date =
CALCULATE(
MAX(data[Date]),
ALL(data[Date].[Date]),
ALL(data[Date].[Day]),
ALL(data[Date].[Month]),
ALL(data[Date].[MonthNo]),
ALL(data[Date].[Quarter]),
ALL(data[Date].[QuarterNo]),
ALL(data[Date].[Year]),
data[Date] <= context_last_date)
RETURN
IF(
-- If there are either no transactions before the end of this period or none after the start, that means we are in a period
-- for which no data exists (e.g. the future) so show nothing
ISBLANK(transactions_after_beginning) || ISBLANK(transactions_before_end),
BLANK(),
CALCULATE(SUM(data[Total]), data[Date].[Date] = transaction_last_date)
)
请注意,在将所有商店聚合在一起时,这不会产生良好的总数。
答案 1 :(得分:0)
> res <- censboot(aml, statMeanSurv, R = 5,
+ var = 1, parallel = "multicore", ncpus = 2)
Warning message:
In parallel::mclapply(seq_len(R), fn, ..., mc.cores = ncpus) :
all scheduled cores encountered errors in user code
>
> res$t
[,1]
[1,] "Error in FUN(X[[i]], ...) : unused argument (var = 1)\n"
[2,] "Error in FUN(X[[i]], ...) : unused argument (var = 1)\n"
[3,] "Error in FUN(X[[i]], ...) : unused argument (var = 1)\n"
[4,] "Error in FUN(X[[i]], ...) : unused argument (var = 1)\n"
[5,] "Error in FUN(X[[i]], ...) : unused argument (var = 1)\n"
根据上表