我正在使用以下查询(在直接查询模式下连接到SQL数据库时)获取前12个月的约会:
df1<- structure(list(myname1 = structure(c(3L, 2L, 1L, 1L), .Label = c("",
"Q15366-2", "Q9Y383"), class = "factor"), myname2 = c(NA, NA,
NA, NA), myname3 = structure(c(1L, 3L, 4L, 2L), .Label = c("A2A3R5",
"D6RDJ1", "P62753", "Q9NX58"), class = "factor"), myname4 = structure(c(2L,
3L, 1L, 1L), .Label = c("", "P62917", "Q14152"), class = "factor")), .Names = c("myname1",
"myname2", "myname3", "myname4"), class = "data.frame", row.names = c(NA,
-4L))
df2 <- structure(list(myname1 = structure(c(3L, 3L, 2L, 2L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L), .Label = c("", "Q15366-2", "Q9Y383"), class = "factor"),
myname2 = structure(c(2L, 3L, 5L, 4L, 6L, 7L, 7L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), .Label = c("", "F8W727", "O76021", "P35527", "P46783",
"Q96C45", "Q9Y383"), class = "factor"), myname3 = structure(c(29L,
33L, 11L, 18L, 1L, 34L, 35L, 22L, 6L, 20L, 21L, 23L, 4L,
10L, 27L, 7L, 2L, 25L, 15L, 24L, 16L, 26L, 13L, 14L, 8L,
9L, 31L, 8L, 9L, 31L, 32L, 17L, 3L, 28L, 12L, 33L, 11L, 19L,
5L, 34L, 30L), .Label = c(" A9Z1X7", " G3V4C1", " H0YGI8",
" O60506-2 ", "A9Z1X7", "B4DT28", "B4DY08", "D6R9X9", "D6RG19",
"E7ETM7", "E9PCT1", "F5H0T1", "G3V2D6", "G3V2Q1", "G3V4W0",
"G3V5V7", "G3XAD8", "M0R088", "M0R088 ", "O43390", "O43390-2",
"O43390-3", "O60506", "P07910", "P07910-2 ", "P07910-3 ",
"P07910-4", "P31948", "P39019", "P42766", "P61927", "Q00839",
"Q8IYB3", "Q8IYB3-2", "S4R3J4"), class = "factor"), myname4 = structure(c(4L,
3L, 10L, 5L, 2L, 9L, 7L, 8L, 6L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("",
"E9PCT1", "P39019", "P61247", "P62917", "Q02543", "Q14152",
"Q15020", "Q15149", "Q9NWH9"), class = "factor")), .Names = c("myname1",
"myname2", "myname3", "myname4"), class = "data.frame", row.names = c(NA,
-41L))
它工作得很好,并使用where子句生成SQL查询,如:
Table.SelectRows(dbo_ReportAppointmentsView, each Date.IsInPreviousNMonths([Date], 12))
问题是,当前月份更改(11月 - > 12月)时,它仍然生成具有完全相同日期的SQL查询。 我预计日期为“2015-12-01”和“2016-12-01”,以显示过去12个月的数据。
按下Power BI桌面中的“刷新”按钮很有帮助,但如果我希望报告自动显示正确的数据,那么它显然不是可维护的解决方案。 这是一个错误还是预期的行为?
答案 0 :(得分:1)
此行为似乎是known issue。
使用针对SQL的Direct Query时,您观察到的行为是一个 传统Direct Query架构的已知问题。我们将成为 在接下来的几个中将SQL Direct Query移动到一个新的架构 几个月,但在那之前,很遗憾没有解决方法 手动刷新。
答案 1 :(得分:0)
如果说“直接查询模式”是指“原生查询”,那么这不是最佳做法,应该避免使用。
除此之外,尝试用类似
的内容替换Date.IsInPreviousNMonths
LocalDT = Date.LocalNow() //May be replaces with desired #date(2016, 11, 25) and likewise
ThisMonthStart = #date(Date.Year(LocalDT), Date.Month(LocalDT), 1),
CompareDate = Date.AddMonths(ThisMonthStart, -12),
Table.SelectRows(dbo_ReportAppointmentsView, each [Date] >= CompareDate)
并查看它是否在查询中生成其他日期。
如果您确实使用了Native Query,那么这可能是与此模式相关的错误。
答案 2 :(得分:0)
检查相对于系统日期(时间)的特定时间段内的日期(时间)的所有函数应解释为“....最后刷新”。
在我看来,这是预期的行为,即使在直接查询模式下运行:在最后刷新时使用查询定义访问最新数据。
我的建议是在SQL数据库中使用当前系统日期(时间)创建一个字段(或者只在它已经可用时使用它)并根据该字段中的值选择数据。