如果是第一个日期或最后一个日期,则使用一个聚合;如果是其他任何一天,请使用另一个聚合

If it is the first date or last date use one aggregation; if any other day, use another aggregation

假设我有以下数据集。

我需要创建以下矩阵,如果它是月初或月末,我在类别 1 中聚合 A 或 B 并计算 SUM 但如果它是一个月中的任何其他日期,但第一天或最后一天,我我在类别 2 中标记 A 或 B 并计算 SUM。我想我需要使用 SWITCH,不是吗?


根据评论编辑信息

喜欢创建 3 列:

isStart = IF ( main_table[date] = STARTOFMONTH ( main_table[date] ), 1, 0 )

isEnd = IF ( main_table[date] = ENDOFMONTH ( 'main_table'[date] ), 1, 0 )

in_between_date =
    IF ( AND ( main_table[date] <> ENDOFMONTH ( 'main_table'[date] ),
               main_table[date] <> STARTOFMONTH ( main_table[date] ) ), 1, 0 )

然后,创建包含我的类别的列,例如

start_end =
    IF ( OR ( NOT ( ISERROR ( SEARCH ( "A", main_table[code] ) ) ),
              main_table[code] = "B" ),
         "Category 1",
         BLANK () )

in_between =
    IF ( OR ( main_table[code] = "B", main_table[code] = "A" ), "Category 2", BLANK () )

但是,我应该在 switch/if 中使用什么? = if(VALUES('main_table'[isStart]) = 1,然后呢?

你在正确的轨道上,但有点过于复杂。您只需要一个额外的列 "Category" 为每行给出该项目属于哪个类别。

Category =
    IF (
        startEnd[date] = STARTOFMONTH ( startEnd[date] )
            || startEnd[date] = ENDOFMONTH ( startEnd[date] );
        "Category1";
        "Category2"
    )

table 最终结果是: