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
ankababu007
Frequent Visitor

Need help with Dax

I have below data set

CustomerSourceSalesAmt
cust-1OMS500
cust-2OMS100
cust-3OMS50
cust-4OMS100
cust-1G5100
cust-2G5200
cust-4G5200
cust-2Onsite300
cust-4Onsite100

 

I have a slicer by  source when I select OMS i should only show cust-1 data as that is the only customer who has only OMS . If we select OMS and G5 then we should show data for cust-1,cust-2,cust-4. based on selection for source we should only display customers that belong to only those sources.

 

This is what the out put I am expecting. Please some one can help in writing a dax for this that will be great

Example-1 
Select OMS
 G5
Result 
cust count1
Sales Amt600
  
Example-2 
Select OMS
 G5
 OnSIte
Result 
cust count2
Sales Amt1000
  
Example-1 
Select OMS
  
Result 
cust count1
Sales Amt50

 

1 ACCEPTED SOLUTION

 

 

Jihwan_Kim_0-1679809547216.png

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

Jihwan_Kim_1-1679718948099.png

 

 

Jihwan_Kim_0-1679718913010.png

 

 

Customer count: = 
VAR _sourcecount =
    COUNTROWS ( DISTINCT ( Source[Source] ) )
VAR _selectedsource =
    DISTINCT ( Source[Source] )
VAR _nonselectedsource =
    EXCEPT ( ALL ( Source[Source] ), _selectedsource )
VAR _customerstable =
    ADDCOLUMNS (
        Data,
        "@sourcecount", COUNTROWS ( FILTER ( Data, Data[Customer] = EARLIER ( Data[Customer] ) ) )
    )
VAR _customerlist =
    SUMMARIZE (
        FILTER ( _customerstable, [@sourcecount] = _sourcecount ),
        Data[Customer]
    )
VAR _exceptcustomerlist =
    SUMMARIZE (
        FILTER ( ALL ( Data ), Data[Source] IN _nonselectedsource ),
        Data[Customer]
    )
VAR _expectedcustomerlist =
    EXCEPT ( _customerlist, _exceptcustomerlist )
RETURN
    COUNTROWS ( _expectedcustomerlist )

 

Customer sales expected result: = 
VAR _sourcecount =
    COUNTROWS ( DISTINCT ( Source[Source] ) )
VAR _selectedsource =
    DISTINCT ( Source[Source] )
VAR _nonselectedsource =
    EXCEPT ( ALL ( Source[Source] ), _selectedsource )
VAR _customerstable =
    ADDCOLUMNS (
        Data,
        "@sourcecount", COUNTROWS ( FILTER ( Data, Data[Customer] = EARLIER ( Data[Customer] ) ) )
    )
VAR _customerlist =
    SUMMARIZE (
        FILTER ( _customerstable, [@sourcecount] = _sourcecount ),
        Data[Customer]
    )
VAR _exceptcustomerlist =
    SUMMARIZE (
        FILTER ( ALL ( Data ), Data[Source] IN _nonselectedsource ),
        Data[Customer]
    )
VAR _expectedcustomerlist =
    EXCEPT ( _customerlist, _exceptcustomerlist )
RETURN
    SUMX (
        FILTER ( Data, Data[Customer] IN _expectedcustomerlist ),
        Data[SalesAmt]
    )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Please find the url for pbix file.I want to see that data in Matrix..

 

https://drive.google.com/file/d/1pHHGbbo-3eaNA-zB_Lld8QN9H08qS1ZZ/view?usp=sharing

 

 

Jihwan_Kim_0-1679809547216.png

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Hi Thank you very much for your solution I think when I am displaying in Matrix its not working as intended to.

ankababu007_0-1679722131854.png

In this image if I select OMS and G5 matrix should show cust-1 with OMS value of 500 and G5 value of 100.

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.

Top Solution Authors