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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
setis
Post Partisan
Post Partisan

USERELATIONSHIP with several conditions

Dear experts, I am struggling with a measure in which I'm trying to combine USERELATIONSHIP and several filters.

 

My measure is thefollowing:

Membership Fee=
CALCULATE (
    [TotalAmountGLEntry];
    USERELATIONSHIP ( '$G_L Entry'[Posting Date]; 'Date'[Date] );
    KEEPFILTERS (
        FILTER (
            ALL (
                '$G_L Entry'[G_L Account No_];
                '$G_L Entry'[Document Type];
                '$G_L Entry'[CUSTOMER]
            );
            '$G_L Entry'[G_L Account No_] = "3011"
                || '$G_L Entry'[G_L Account No_] = "3016"
                || '$G_L Entry'[Document Type] = 2
                || '$G_L Entry'[CUSTOMER] <> BLANK ()
        )
    )
)


My problem is that USERELATIONSHIP works but the rest of the filters do not

 

I have tried different things like combining FILTER and VALUES instead of KEEPFILTERS but the problem is that I can't get both the USERELATIONSHIP and the FILTERS to work at the same time. 

 

Can anyone see where the error is?

 

Thank you in advance 

1 ACCEPTED SOLUTION

@Mariusz and @amitchandak 

 

It worked for me doing:

 

 

 

 

Membership Fee = 
VAR Acc3011 = 
CALCULATE (
    [TotalAmountGLEntry];
    USERELATIONSHIP ( '$G_L Entry'[Posting Date]; 'Date'[Date] );
    USERELATIONSHIP('$G_L Entry'[CUSTOMER];'All Customers'[No_]);
    KEEPFILTERS ('$G_L Entry'[G_L Account No_] = "3011");
    KEEPFILTERS ('$G_L Entry'[Document Type] = 2);
    KEEPFILTERS('$G_L Entry'[CUSTOMER] <> BLANK())

        )
VAR Acc3016 = 
CALCULATE (
    [TotalAmountGLEntry];
    USERELATIONSHIP ( '$G_L Entry'[Posting Date]; 'Date'[Date] );
    USERELATIONSHIP('$G_L Entry'[CUSTOMER];'All Customers'[No_]);
    KEEPFILTERS ('$G_L Entry'[G_L Account No_] = "3016");
    KEEPFILTERS ('$G_L Entry'[Document Type] = 2);
    KEEPFILTERS('$G_L Entry'[CUSTOMER] <> BLANK())

        )
RETURN
Acc3011+Acc3016

 

 

 

View solution in original post

11 REPLIES 11
Mariusz
Community Champion
Community Champion

Hi @setis 

 

Try this, if not working try without KEEPFILTERS

Membership Fee = 
CALCULATE (
    [TotalAmountGLEntry];
    KEEPFILTERS (
        FILTER (
            CALCULATETABLE(
                ALL (
                    '$G_L Entry'[G_L Account No_];
                    '$G_L Entry'[Document Type];
                    '$G_L Entry'[CUSTOMER]
                );
                USERELATIONSHIP ( '$G_L Entry'[Posting Date]; 'Date'[Date] )
            );
            '$G_L Entry'[G_L Account No_] = "3011"
                || '$G_L Entry'[G_L Account No_] = "3016"
                || '$G_L Entry'[Document Type] = 2
                || '$G_L Entry'[CUSTOMER] <> BLANK ()
        )
    )
)
Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

 

@Mariusz Thanks again!

 

Unfortunately it didn't work either with or without KEEPFILTERS. I'm getting lines for all different G_L Account No_

@Mariusz and @amitchandak 

 

It worked for me doing:

 

 

 

 

Membership Fee = 
VAR Acc3011 = 
CALCULATE (
    [TotalAmountGLEntry];
    USERELATIONSHIP ( '$G_L Entry'[Posting Date]; 'Date'[Date] );
    USERELATIONSHIP('$G_L Entry'[CUSTOMER];'All Customers'[No_]);
    KEEPFILTERS ('$G_L Entry'[G_L Account No_] = "3011");
    KEEPFILTERS ('$G_L Entry'[Document Type] = 2);
    KEEPFILTERS('$G_L Entry'[CUSTOMER] <> BLANK())

        )
VAR Acc3016 = 
CALCULATE (
    [TotalAmountGLEntry];
    USERELATIONSHIP ( '$G_L Entry'[Posting Date]; 'Date'[Date] );
    USERELATIONSHIP('$G_L Entry'[CUSTOMER];'All Customers'[No_]);
    KEEPFILTERS ('$G_L Entry'[G_L Account No_] = "3016");
    KEEPFILTERS ('$G_L Entry'[Document Type] = 2);
    KEEPFILTERS('$G_L Entry'[CUSTOMER] <> BLANK())

        )
RETURN
Acc3011+Acc3016

 

 

 

Mariusz
Community Champion
Community Champion

Hi @setis 

 

Try this 

Membership Fee = 
CALCULATE(
    CALCULATE (
        [TotalAmountGLEntry];
        KEEPFILTERS (
            FILTER (
                ALL (
                    '$G_L Entry'[G_L Account No_];
                    '$G_L Entry'[Document Type];
                    '$G_L Entry'[CUSTOMER]
                );
                '$G_L Entry'[G_L Account No_] = "3011"
                    || '$G_L Entry'[G_L Account No_] = "3016"
                    || '$G_L Entry'[Document Type] = 2
                    || '$G_L Entry'[CUSTOMER] <> BLANK ()
            )
        )
    );
    USERELATIONSHIP ( '$G_L Entry'[Posting Date]; 'Date'[Date] )
)
Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.



Dear @Mariusz 

Thanks for your answer. It didn´t work for me. 

 

Neither the filters or the userelationship is working on this one. 

amitchandak
Super User
Super User

In "calculate" use suitable function like sumx, countx on [TotalAmountGLEntry] and the move filter in the first parameter of table name and try.

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks.

My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p...

https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Dear @amitchandak 

Thanks for your answer. 

I'm not sure I understood exactly what you mean. 

 

I tried this, but it didn't work:

Membership Fee = 
CALCULATE (
    SUMX(       
         KEEPFILTERS (
        FILTER (
            ALL (
                '$G_L Entry'[G_L Account No_];
                '$G_L Entry'[Document Type];
                '$G_L Entry'[CUSTOMER]
            );
            '$G_L Entry'[G_L Account No_] = "3011"
                || '$G_L Entry'[G_L Account No_] = "3016"
                || '$G_L Entry'[Document Type] = 2
                || '$G_L Entry'[CUSTOMER] <> BLANK ()
        )
    );
    SUM('$G_L Entry'[Amount]));USERELATIONSHIP('$G_L Entry'[Posting Date];'Date'[Date])
)

 

Try Like. No need sum inside sumx, unless there is a need. Also ,check if it can work without keep filter.

 

Membership Fee = 
CALCULATE (
    SUMX(       
         KEEPFILTERS (
        FILTER (
            ALL (
                '$G_L Entry'[G_L Account No_];
                '$G_L Entry'[Document Type];
                '$G_L Entry'[CUSTOMER]
            );
            '$G_L Entry'[G_L Account No_] = "3011"
                || '$G_L Entry'[G_L Account No_] = "3016"
                || '$G_L Entry'[Document Type] = 2
                || '$G_L Entry'[CUSTOMER] <> BLANK ()
        )
    );
    ('$G_L Entry'[Amount]));USERELATIONSHIP('$G_L Entry'[Posting Date];'Date'[Date])
)

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

If this can work

Membership Fee = 
CALCULATE (
    SUMX(       
         
        FILTER (
            '$G_L Entry';
            '$G_L Entry'[G_L Account No_] = "3011"
                || '$G_L Entry'[G_L Account No_] = "3016"
                || '$G_L Entry'[Document Type] = 2
                || '$G_L Entry'[CUSTOMER] <> BLANK ()
        )
    ;
    ('$G_L Entry'[Amount]));USERELATIONSHIP('$G_L Entry'[Posting Date];'Date'[Date])
)
Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Dear @amitchandak 
In this one: 

Membership Fee = 
CALCULATE (
    SUMX(       
         
        FILTER (
            '$G_L Entry';
            '$G_L Entry'[G_L Account No_] = "3011"
                || '$G_L Entry'[G_L Account No_] = "3016"
                || '$G_L Entry'[Document Type] = 2
                || '$G_L Entry'[CUSTOMER] <> BLANK ()
        )
    ;
    ('$G_L Entry'[Amount]));USERELATIONSHIP('$G_L Entry'[Posting Date];'Date'[Date])
)


USERELATIONSHIP works but the filters do not. 

 If possible please share a sample pbix file after removing sensitive information.
Thanks

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.