Searching for DAX formula - equivalent to Excel SUMIF

自古美人都是妖i 提交于 2019-12-11 15:38:49

问题


I am searching for a DAX formula.

Specifically:

If SOLD (1st column) = count volume (second column), if not SOLD = 0 

I need to reflect the volume of SOLD in a new column. UNSOLD Volumes should be 0.

I attach the reduced data set.


回答1:


If I understand, you want to only perform aggregation when the SOLD_UNSOLD column is equal to "SOLD", otherwise return 0? If so, the following formula will do this, you'll just need to update the column names accordingly. The outer IF prevents problems resulting from further evaluation (i.e. grand totals) and it's necessary to wrap the column in the VALUES function as this will turn the column into a table of the unique values of it.

'YourTable'[CountOfSold] =
    IF (
        COUNTROWS ( VALUES ( YourTable[SOLD_UNSOLD] ) ) = 1,
        IF (
            VALUES ( YourTable[SOLD_UNSOLD] ) = "SOLD",
            COUNT ( YourTable[ColumnToAggregate] ),
            0
        ),
        0
    )



回答2:


The Excel SUMIF is closest to the DAX SUMX.

I'm not positive I'm understanding what you are asking for, but I think you'd want something like this:

SOLD_VOLUME = SUMX(Table1,
                   IF(Table1[SOLD_UNSOLD] = "SOLD",
                      Table1[DAILY_VOLUME],
                      0
                   )
              )

You could also do this with a filter:

SOLD_VOLUME = SUMX(
                  FILTER(
                      Table1,
                      Table1[SOLD_UNSOLD] = "SOLD"
                  ),
                  Table1[DAILY_VOLUME]
              )


来源:https://stackoverflow.com/questions/53502404/searching-for-dax-formula-equivalent-to-excel-sumif

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