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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.