Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Need help for Dax expression

Hi,

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)

4 REPLIES 4
TomMartens
Super User
Super User

Hey,

 

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.

 

Regards,

Tom



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
PattemManohar
Community Champion
Community Champion

@Anonymous 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 PBI Community Champion




Anonymous
Not applicable

Hi,

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

Capture152.PNG

Hi @Anonymous,

 

Add a MIN if that formula is the solution.

 

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

 

Best Regards,
Dale

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

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.