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

Dax to Filter combinations of values

Hi Community,

 

Thanks for helping me earlier today. But now I am stuck with a new issue. In the following snapshot, I want to show invoices with only any combinations of (23 and 44 or 200 or 201 or 203)  OR (36 and 44 or 200 or 201 or 203) service codes, so the red crossed invoices should not appear in the matrix:  Sample PBi is attached.

Capture2.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

My sample pbi is attached:

https://1drv.ms/u/s!Ag919_pO_UKrgQLIOrUlBri_AeVY?e=6nDoTc

Thanks in advance!

Meena

1 ACCEPTED SOLUTION

OK, @Anonymous I *believe* I have this. Required a minor tweak, using your new PBIX. File is attached. Let me know if this works but I may not be able to get back to it until tomorrow. It's pretty late here and I need sleep.

 

Complex Selector = 
    VAR __ID = MAX('Table'[invoiceid])
    VAR __specialCodes = { 23, 36 }
    VAR __otherCodes = EXCEPT(DISTINCT(ALLSELECTED('Table'[Service code])),__specialCodes)
    VAR __table1 = SELECTCOLUMNS(FILTER(ALL('Table'),[Service code] IN __specialCodes),"__ID1",[invoiceid])
    VAR __table2 = SELECTCOLUMNS(FILTER(ALL('Table'),[Service code] IN __otherCodes),"__ID2",[invoiceid])
    VAR __table3 = ADDCOLUMNS(__table1,"__CountOther",COUNTX(FILTER(__table2,[__ID2] = [__ID1]),[__ID2]))
    VAR __table4 = SELECTCOLUMNS(FILTER(__table3,[__CountOther]>0),"__serviceID",[__ID1])
RETURN
    IF(__ID IN __table4,1,BLANK())

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

9 REPLIES 9
Greg_Deckler
Super User
Super User

You should be able to implement a variation of my Inverse Selector quick measure: https://community.powerbi.com/t5/Quick-Measures-Gallery/Inverse-Selector/m-p/648290#M325

 

Just construct your measure so that it meets your logic.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks @Greg_Deckler , Your inverse selection measure is great. But it doesnt give me the combination pattern I am after..

Correct, you need to adjust the measure so that it implements your selection logic. If you can provide sample data I can probably whip it together for you. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hey @Anonymous , I have this almost working the way I want. I have it so that it at least shows the right invoiveid's. However, I need to tweak it to get it to display all of the GP Codes for those invoiceids. Need to think about it a bit but figured I would pass along what I have so far.

 

See attached file that implements this measure:

Complex Selector = 
    VAR __ID = MAX('Table'[invoiceid])
    VAR __specialCodes = { 23, 36 }
    VAR __otherCodes = EXCEPT(VALUES('Table'[Service code]),__specialCodes)
    VAR __table1 = SELECTCOLUMNS(FILTER(ALL('Table'),[Service code] IN __specialCodes),"__ID1",[invoiceid])
    VAR __table2 = SELECTCOLUMNS(FILTER(ALL('Table'),[Service code] IN __otherCodes),"__ID2",[invoiceid])
    VAR __table3 = ADDCOLUMNS(__table1,"__CountOther",COUNTX(FILTER(__table2,[__ID2] = [__ID1]),[__ID2]))
    VAR __table4 = SELECTCOLUMNS(FILTER(__table3,[__CountOther]>0),"__serviceID",[__ID1])
RETURN
    IF(__ID IN __table4,1,BLANK())

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler  thanks a lot for your time & effort. Please use the following sample pbi:

https://1drv.ms/u/s!Ag919_pO_UKrgQLIOrUlBri_AeVY?e=T6FhsZ

The one that you are using doesnt have complete meaningful data set.

OK, @Anonymous I *believe* I have this. Required a minor tweak, using your new PBIX. File is attached. Let me know if this works but I may not be able to get back to it until tomorrow. It's pretty late here and I need sleep.

 

Complex Selector = 
    VAR __ID = MAX('Table'[invoiceid])
    VAR __specialCodes = { 23, 36 }
    VAR __otherCodes = EXCEPT(DISTINCT(ALLSELECTED('Table'[Service code])),__specialCodes)
    VAR __table1 = SELECTCOLUMNS(FILTER(ALL('Table'),[Service code] IN __specialCodes),"__ID1",[invoiceid])
    VAR __table2 = SELECTCOLUMNS(FILTER(ALL('Table'),[Service code] IN __otherCodes),"__ID2",[invoiceid])
    VAR __table3 = ADDCOLUMNS(__table1,"__CountOther",COUNTX(FILTER(__table2,[__ID2] = [__ID1]),[__ID2]))
    VAR __table4 = SELECTCOLUMNS(FILTER(__table3,[__CountOther]>0),"__serviceID",[__ID1])
RETURN
    IF(__ID IN __table4,1,BLANK())

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler  really appreciate you help! Thanks😊 You are a saviour🤗

My pleasure @Anonymous! Have a good night! 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.