DAX Total by category displayed for single category

♀尐吖头ヾ 提交于 2021-02-10 16:42:54

问题


I want a total by category for single category. Just like the FruitOnly measure in a picture:

I have a measure:

Total by category = CALCULATE([Sales], ALLEXCEPT('Table','Table'[Category]))

But I want the results only for Fruit, having blanks for all the other categories.

FruitOnly = IF(MAX('Table'[Category])="Fruit", [Total by category], BLANK())

Such a result is cripple because there is no total sum for that measure which should be 45.

Wouldn't there be any simpler way to get the FruitOnly results? Just like the measure:

Fruits raw sales = CALCULATE([Sales], 'Table'[Category]="Fruit")

returns the results only for fruits?

And now the bonus question lifting the challenge to Darth Vader level. Would a measure resulting in FruitOnly be possible if there was no Category displayed in table visual, just Product?

My desperate efforts are here in a file to download:

TotalByCategoryForSingleCategory.pbix


回答1:


This will do the trick:

FruitOnly =
CALCULATE (
    [Total by category],
    FILTER ( 'Table', 'Table'[Category] = "Fruit" )
)

I tried it out with your .pbix and I got the following:



来源:https://stackoverflow.com/questions/57596116/dax-total-by-category-displayed-for-single-category

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