Showing results for 
Search instead for 
Did you mean: 
Helper III
Helper III

Need help for Dax expression


I need to implement the below logic in DAX


If Direction = Inbound then COUNT DISTINCT (GS_SENDER_ID) else If Direction = Outbound then COUNT DISTINCT (GS_RECEIVER_ID)


and I have written the below code for first condition:


Partner Count = CALCULATE(DISTINCTCOUNT(Test[GS_SENDER_ID]), Test[Direction] = "I") , but how can I implement the 2nd condition here?

else If Direction = Outbound then COUNT DISTINCT (GS_RECEIVER_ID)

Super User II
Super User II



maybe it is as simple as @PattemManohar already mentioned or it is much more complex.


I'm assuming that your dataset is about some kind of shipments and one shipment is either inbound (I) or outbund (O).

Now if you filter this dataset may contain rows that are eihter I or O, but nevertheless you need to know the number of distinct partners that have been engaged with the shipment.


I'm wondering if a partner can be either SENDER or RECEIVER depending on the direction of the shipment? And if this may be the case, if the same ID is used, and if you want a partner to be counted once no matter of the role the partner is playing?


Maybe you might consider to provide some sample data, upload the pbix to onedrive or dropbox and share the link.


Somehow, I'm hoping that the complexity of your question is of the latter 🙂 This will be fun.




Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Community Champion
Community Champion

@dsandip59 Please try this..


CountResult = 

VAR _InboundCount = CALCULATE(DISTINCTCOUNT(Test[GS_SENDER_ID]),Test[Direction]="I")
VAR _OutboundCount = CALCULATE(DISTINCTCOUNT(Test[GS_RECEIVER_ID]),Test[Direction]="O")

RETURN IF(Test[Direction]="I",_InboundCount,_OutboundCount)

Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


I have used your expression and it gives me a error like below screen shot:


Hi @dsandip59,


Add a MIN if that formula is the solution.


if(MIN('Test'[Direction]) = "I", 


Best Regards,

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources


Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors