我正在尝试创建一个板块,告诉我每月最近3个月的活跃用户,我有一个日历表,其中包含2020年每月的最后一天,其想法是,当我单击03 /我将在31/2020年内显示过去3个月内已登录用户的独特数量的数据。
每个栏都必须出现
ggplot(df, aes(x = x, y = y)) +
geom_point() +
stat_smooth(method = "lm", formula = y ~ x,
size = 1, se = FALSE, aes(color = "a")) +
stat_smooth(method = "lm", formula = y ~ poly(x, 2),
size = 1, se = FALSE, aes(color = "b")) +
stat_smooth(method = "lm", formula = y ~ poly(x, 3),
size = 1, se = FALSE, aes(color = "c")) +
stat_smooth(method = "gam", formula = y ~ s(x),
size = 1, se = FALSE, aes(color = "d")) +
theme(legend.justification = c(1, 1),
legend.position = c(0.45, 0.45),
legend.title = element_blank()) +
scale_color_manual(values = c("black", "green", "orange", "blue"),
labels = c("linear", "quadratic", "cubic", "smooth"))
如果我单击2020年4月30日
January (count from 11/01/2019 to 01/31/2020)
February (count from 12/01/2019 to 02/29/2019)
March (count from 01/01/2020 to 03/31/2020)
我该如何使用DAX中的一项措施?
我附上一张我想做的事的图片。
答案 0 :(得分:1)
我的问题已通过以下dax代码解决:
Login Count = CALCULATE(DISTINCTCOUNT(user_logins[key]), FILTER(ALLEXCEPT(user_logins,user_logins[chanel]), user_logins[login_date]>=date(YEAR(MIN(calendar[Date])), month(MIN(calendar[Date]))-2,1) && user_logins[login_date]<date(YEAR(MIN(calendar[Date])), month(MIN(calendar[Date]))+1,1)))
感谢先生的帮助。巴拉吉
答案 1 :(得分:0)
创建一个使用DatesInPeriod()的度量,如下所示:
3 Month Distict Count =
CALCULATE(
DISTINCTCOUNT(YourTableName[CountColumn]),
DATESINPERIOD('Calendar'[Date]),
LASTDATE('Calendar'[Date]),
-3,
MONTH))