Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

powerbi - Equivalent concept for MDX as Keepfilters

we are using a multidimensional cube with power bi as the visual layer and i have some problems with a measure that should be quite simple but i dont know mdx/multidim very well.

How can i get the same result as (for contoso db) as a MDX Measure (that i can use in power bi in an equivalent way):

Sales Amount red Products = 
CALCULATE(
    SUMX(Sales, Sales[Quantity] * Sales[Net Price]),
    KEEPFILTERS('Product'[Color] = "Red")
)

I have a working measure that produces the correct results but it is too slow if more dimensions are shown in the power bi table:

    Create Member Currentcube.[Measures].[Sales Amount red Products]
as iif(  ( [Measures].[Sales Amount],[Product].[Color].&[Red]) <> 0 
        AND ([Product].[Color].currentmember is [Product].[Color].&[Red] 
    OR [Product].[Color].currentmember is [Product].[Color].[all]) ,
([Measures].[Sales Amount],[Product].[Color].&[Red] ) ,NULL)
question from:https://stackoverflow.com/questions/66059846/equivalent-concept-for-mdx-as-keepfilters

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

KEEPFILTERS ensures it doesn’t show Red sales when looking at other colors. The equivalent in MDX would be:

Create Member Currentcube.[Measures].[Sales Amount red Products]
as null;

Scope({[Product].[Color].&[Red], [Product].[Color].[All]});
  [Measures].[Sales Amount red Products] = ([Measures].[Sales Amount], [Product].[Color].&[Red]);
End Scope;

A Scope statement is a more efficient way of doing an IIF.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...