简体   繁体   English

Power Bi Dax:在上个月的两个日期之间过滤

[英]Power Bi Dax: Filter between 2 dates of the previous month

I need some help with a filter.我需要过滤器方面的帮助。

The filter needs to filter date between the 16th of one month and the 15th of the next month, this should be for the previous months when looking at the data so if you look at it on March it will show data between 16th of Jan to 15th of Feb.过滤器需要过滤一个月 16 日到下个月 15 日之间的日期,这应该是查看数据时的前几个月,所以如果你在 3 月查看它,它将显示 1 月 16 日到 15 日之间的数据二月

The data is 'Duration' of days which i will total up for the between 16th-15th period.数据是天数的“持续时间”,我将在第 16 至第 15 个期间进行总计。

I have a measure for this but I'm not sure how it would go into my table visual to show the right data:我对此有一个衡量标准,但我不确定它如何进入我的表格可视化以显示正确的数据:

Assessment Date =
IF (
    DAY ( TODAY () ) < 16,
    DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 15 ),
    DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 15 )
)

Is there a way I can put this measure into a new formula and do it like that?有没有办法可以将此度量放入一个新公式中并像那样做? or is there another formula i could use?或者我可以使用其他公式吗?

You could use variables and try something like this:您可以使用变量并尝试这样的事情:

Duration = 
VAR Start1 = 
        DATE(
            IF(MONTH(TODAY())<=2,YEAR(TODAY())-1,YEAR(TODAY())),
            IF(MONTH(TODAY())=1,11,IF(MONTH(TODAY())=2,12,MONTH(TODAY())-1)),
            16)
VAR End1 = 
        DATE(
            IF(MONTH(TODAY())=1,YEAR(TODAY())-1,YEAR(TODAY())),
            IF(MONTH(TODAY())=1,12,MONTH(TODAY())-1),
            15)
VAR Calc =
        IF(Table[Date]>=Start1 && Table[Date]<=End1,Table[Duration],0)
RETURN Calc

This would return values for only those rows which fall into the date filter.这将只返回属于日期过滤器的那些行的值。 I am not sure if I got your date filter condition correctly.我不确定我是否正确获取了您的日期过滤条件。 Either way, you should be able to adjust the calculation to get your desired results.无论哪种方式,您都应该能够调整计算以获得所需的结果。 Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM