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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
hosea_chumba
Helper I
Helper I

Query on DAX Equation

Kindly assist with the below;

Consider the table below:

Client IDLoan Product ID
1Education
2Crop
3Education
4Animal
1Crop
1Water
4Education

I would like to identify client IDs that got "Education" loan product ID but did not get any other loan product ID, and also to identify client IDs that got "Education" loan product ID plus any other loan product ID.

Please help Nested Filter DAX Query 

1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

@hosea_chumba create this calculated column:

 

Status = 
VAR _current_client = 'Table'[Client ID]
VAR _client_products = 
    CONCATENATEX(FILTER('Table', 'Table'[Client ID] = _current_client), 'Table'[Loan Product ID], ", ")
VAR _client_products_without_education = 
    CONCATENATEX(FILTER('Table', 'Table'[Client ID] = _current_client && 'Table'[Loan Product ID] <> "Education"), 'Table'[Loan Product ID], ", ")
VAR _has_education = CONTAINSSTRINGEXACT(_client_products, "Education")
VAR _has_anything_else = NOT( ISBLANK(_client_products_without_education)) 
VAR _result = 
    SWITCH(
        TRUE(),
        _has_education && _has_anything_else, "Education + more",
        _has_education && NOT(_has_anything_else), "Only Education",
        "No Education"
    )
RETURN
    _result

 

SpartaBI_0-1656580276272.png

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

View solution in original post

5 REPLIES 5
tamerj1
Super User
Super User

Hi @hosea_chumba 
Here is a sample file with the solution for both calculated column and measure options https://we.tl/t-tw6wKBDwJt

1.png2.png

Falg Column = 
VAR CurrentClientTable =
    CALCULATETABLE ( Loans, ALLEXCEPT ( Loans, Loans[Client ID] ) )
VAR CurrntLoan =
    Loans[Loan Product ID]
RETURN
    IF (
        COUNTROWS ( CurrentClientTable ) = 1 
            && CurrntLoan = "Education",
            1
    )
Falg Measure = 
SUMX (
    VALUES ( Loans[Client ID] ),
    IF ( 
        COUNTROWS ( CALCULATETABLE ( Loans, ALLEXCEPT ( Loans, Loans[Client ID] ) ) ) = 1 
            && CALCULATE ( SELECTEDVALUE ( Loans[Loan Product ID] ) ) = "Education",
            1,
            0
    )
)
SpartaBI
Community Champion
Community Champion

@hosea_chumba create this calculated column:

 

Status = 
VAR _current_client = 'Table'[Client ID]
VAR _client_products = 
    CONCATENATEX(FILTER('Table', 'Table'[Client ID] = _current_client), 'Table'[Loan Product ID], ", ")
VAR _client_products_without_education = 
    CONCATENATEX(FILTER('Table', 'Table'[Client ID] = _current_client && 'Table'[Loan Product ID] <> "Education"), 'Table'[Loan Product ID], ", ")
VAR _has_education = CONTAINSSTRINGEXACT(_client_products, "Education")
VAR _has_anything_else = NOT( ISBLANK(_client_products_without_education)) 
VAR _result = 
    SWITCH(
        TRUE(),
        _has_education && _has_anything_else, "Education + more",
        _has_education && NOT(_has_anything_else), "Only Education",
        "No Education"
    )
RETURN
    _result

 

SpartaBI_0-1656580276272.png

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

Hi Sparta,

Why did you use Concatenatex and filter i.e. "concatenatex(filter", as in what is the logic behind it. I know concatenatex returns combined items in each row however i need to understand what it does when you add a filter.

@hosea_chumba it does exactly the same, I just gave him a filtered table to work on so it will have only the relevant values to concatenate

Is it possible to use Calculate in place of Concatenatex and arrive at the same solution?

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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