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

DAX to Filter on the same field with different conditions

This is a sample data table. My requirement is to calculate:
How may People who are from Marketing in 2018 were part of 2017 Sales? Answer is : 4 (C,D,E & F)

I am not sure if this has a simple trick to calculate in dax  but I am not able to answer .

 

NameYearProgram
A2017Sales
B2017Sales
C2017Sales
D2017Sales
E2017Sales
F2017Sales
G2017Sales
A2017Marketing
B2017Marketing
C2017Marketing
H2018Sales
I2018Sales
J2018Sales
K2018Sales
L2018Sales
C2018Marketing
D2018Marketing
E2018Marketing
F2018Marketing
2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

@Sabarikumar7579,
if you are looking to count the number of rows, create a measure like this:

Count of Name = 
VAR t1 = NATURALINNERJOIN (
    SELECTCOLUMNS (
        FILTER ( Table1, Table1[Year] = 2018 && Table1[Program] = "Marketing" ),
        "Name", [Name]
    ),
    SELECTCOLUMNS (
        FILTER ( Table1, Table1[Year] = 2017 && Table1[Program] = "Sales" ),
        "Name", [Name]
    )
)
RETURN COUNTROWS(t1)

Otherwise, if you are looking for a list, use this instead:

List of Name = 
VAR t1 = NATURALINNERJOIN (
    SELECTCOLUMNS (
        FILTER ( Table1, Table1[Year] = 2018 && Table1[Program] = "Marketing" ),
        "Name", [Name]
    ),
    SELECTCOLUMNS (
        FILTER ( Table1, Table1[Year] = 2017 && Table1[Program] = "Sales" ),
        "Name", [Name]
    )
)
RETURN CONCATENATEX(t1, [Name], ", ")

View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

 

You may download my PBI file from here.

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

 

You may download my PBI file from here.

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you So much

@Ashish_Mathur and @Anonymous

 

Both your functions worked. Learnt something new.

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

@Sabarikumar7579,
if you are looking to count the number of rows, create a measure like this:

Count of Name = 
VAR t1 = NATURALINNERJOIN (
    SELECTCOLUMNS (
        FILTER ( Table1, Table1[Year] = 2018 && Table1[Program] = "Marketing" ),
        "Name", [Name]
    ),
    SELECTCOLUMNS (
        FILTER ( Table1, Table1[Year] = 2017 && Table1[Program] = "Sales" ),
        "Name", [Name]
    )
)
RETURN COUNTROWS(t1)

Otherwise, if you are looking for a list, use this instead:

List of Name = 
VAR t1 = NATURALINNERJOIN (
    SELECTCOLUMNS (
        FILTER ( Table1, Table1[Year] = 2018 && Table1[Program] = "Marketing" ),
        "Name", [Name]
    ),
    SELECTCOLUMNS (
        FILTER ( Table1, Table1[Year] = 2017 && Table1[Program] = "Sales" ),
        "Name", [Name]
    )
)
RETURN CONCATENATEX(t1, [Name], ", ")
Greg_Deckler
Super User
Super User

Hmm, that's some pretty ugly data. I think to do this correctly, you would need something to determine the last status of 2017.


@ 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.