How to calculate using the same measure when date has no value (past and future)?

一曲冷凌霜 提交于 2020-01-06 08:08:39

问题


After trying a lot of approaches and formulas I decided to ask this question.

See this Matrix visual:

WeekDate is column in a table called Planning. It's related to another date time column in another table called Export.

Export table only has values for the dates: 23-Dec-19, 30-Dec-19 and 06-Jan-20 whereas Planning table has dates spanning multiple weeks in the past and in the future.

Cumulative Plan Count is calculating correctly as long as there are matching dates between the tables Planning and Export.

Now I'd like to keep calculating even when there's no date matching. I want to get the value 32 from the FIRSTDATE which has data (in this case 23-Dec-2019) and backfill the past with 32.

For dates in the future I'd like to use LASTDATE (06-Jan-20) value which is 89. Something like this:

WeekDate          Cumulative Plan Count
.
.
.
25-Nov-19         32
02-Dec-19         32 
09-Dec-19         32
16-Dec-19         32
23-Dec-19         32 <= First WeekDate which has data
30-Dec-19         57
06-Jan-19         89 <= Last WeekDate which has data
13-Jan-20         89
20-Jan-20         89
27-Jan-20         89
.
.
.

The formula used for the cumulative SUM is this:

Cumulative Plan Count = 

CALCULATE (
    ROUNDUP([1 - Target] * MAX(Planning[1 - Plan]), 0)
    ,
    FILTER (
        ALL ( Planning[WeekDate] ),
        Planning[WeekDate] <= MAX(Planning[WeekDate])
    )
)

####### Edit 1 #######

Using this measure below I get 1s for the past...

1 - Target = 

VAR minWeek = MIN(Export[Week_Imported])

VAR targetCount =
CALCULATE (
        COUNT( 'Export'[1 - Plan]),
        FILTER('Export', OR(Export[1 - Plan]="YES", Export[1 - Plan]="_")))

var minTarget = CALCULATE (
        COUNT( 'Export'[1 - Plan]),
        FILTER('Export', OR(Export[1 - Plan]="YES", Export[1 - Plan]="_")
        && Export[Week_Imported] = minWeek))

RETURN

SWITCH(TRUE,
targetCount = BLANK(),  1, // Here is where I need to get the 1st row value (32) and fill up the column up above...
targetCount)

The problem is that no matter what I do I can't get the 1st value for 23-Dec-2019 (32) to fill up the Cumulative Plan Count column.

This is the result when I use the formula above:

WeekDate          Cumulative Plan Count
.
.
.
25-Nov-19         1
02-Dec-19         1 
09-Dec-19         1
16-Dec-19         1
23-Dec-19         32 <= First WeekDate which has data
30-Dec-19         57
06-Jan-19         89 <= Last WeekDate which has data
13-Jan-20         89
20-Jan-20         89
27-Jan-20         89
.
.
.

来源:https://stackoverflow.com/questions/59584790/how-to-calculate-using-the-same-measure-when-date-has-no-value-past-and-future

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!