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
1.1k views
in Technique[技术] by (71.8m points)

powerbi - DAX options to filter 1 side on 1:M relationship

I have salesman dimension and sales fact with 1:M relationship on salesman_id.

I am trying to create a measure for count of salesman that have made sales in location is 6.

CALCULATE (
      DISTINCTCOUNT ( Salesman[SalesmanKey] ),
      Sales,
      Sales[LocationId] = 6
)

I think this is not working because the filter doesn't flow from sales into salesman table.

I could change the filter direction as both but I'm looking at other option like using DAX CALCULATE with CROSSFILTER. Is there any other option like using CALCULATETABLE?

question from:https://stackoverflow.com/questions/65864106/dax-options-to-filter-1-side-on-1m-relationship

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

1 Reply

0 votes
by (71.8m points)

You can use the following Dax formula to achieve your goal:

Measure = 
    CALCULATE(
        DISTINCTCOUNT( Salesman[SalesmanKey] ),
        CROSSFILTER( Sales[salesman_id], Salesman[SalesmanKey], Both ),
        Sales[LocationId] = 6
    )

However I recomend you using the salesman id from the fact table:

Measure = 
    CALCULATE(
        DISTINCTCOUNT( Sales[salesman_id] ),
        Sales[LocationId] = 6
    )

Edit: i added the option using the calculatetable:

Measure = 
CALCULATE(
    DISTINCTCOUNT( Salesman[SalesmnaKey] ),
    CALCULATETABLE(
        Sales,
        Sales[LotacionId] = 6
    )
)

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

...