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
setis
Post Partisan
Post Partisan

COUNTIF case in A but not in B

Hi all,

 

I hope that you can help me with this. 

 

I have 3 tables with the following relationships:

 

[Fees]*--->1[Cases]1<---*[Financial] 

 

I would like to have a measure to calculate the number of cases that are in [Fees] but not in [Financial]

 

I have a card with the following measure:

 

NrCasesFee&NOPayment = CALCULATE (
            DISTINCTCOUNT(Fees[CaseID]);
            FILTER (
                ALL (Fees[CaseID]);
                CALCULATE(SUM(Financial[Amount Paid]))=0
            )
)
My issue is that when I select a case in the table [Fees] and the case is not in [Financial], the measure works (showing "1")
 
However, when nothing is selected, instead of showing the Nr of cases in [Fees] that are not in [Financial], it shows "Blank"
 
What am I doing wrong?
 
Thanks in advance!
2 ACCEPTED SOLUTIONS

@setis 

I see

You have to modify the filtering in the CALCULATETABLE then. Right now we are just filtering for amount > 0 and that is why the row > 0 is taken into account. You want SUM(amount) > 0 as we do working out the second listing.

 

 

NrCasesPayment&NOFee =
COUNTROWS (
    EXCEPT (
        FILTER (
            DISTINCT ( Financial[CaseID] );
            CALCULATE ( SUM ( Financial[Amount Paid] ) ) > 0
        );
        FILTER (
            DISTINCT ( Cases[CaseID] );
            CALCULATE ( SUM ( Fees[Amount Paid] ) ) > 0
        )
    )
)

 

which if I'm not mistaken should be equivalent to this with your set-up:

 

NrCasesPayment&NOFee =
COUNTROWS (
    EXCEPT (
        FILTER (
            DISTINCT ( Cases[CaseID] );
            CALCULATE ( SUM ( Financial[Amount Paid] ) ) > 0
        );
        FILTER (
            DISTINCT ( Cases[CaseID] );
            CALCULATE ( SUM ( Fees[Amount Paid] ) ) > 0
        )
    )
)

 and to this:

 

NrCasesPayment&NOFee =
COUNTROWS (
    EXCEPT (
        FILTER (
            DISTINCT ( Financial[CaseID] );
            CALCULATE ( SUM ( Financial[Amount Paid] ) ) > 0
        );
        FILTER (
            DISTINCT ( Fees[CaseID] );
            CALCULATE ( SUM ( Fees[Amount Paid] ) ) > 0
        )
    )
)

View solution in original post

@setis 

 

For this to work well, all IDs with payment in 'Financials' would need to be in 'Fees' (either with or without payment). That seems not to be the case.  The missing ones will not be removed by the EXCEPT. 

A safer, less restrictive option is to go with INTERSECT:

 

NrCases Payments&Fees2 = 
COUNTROWS(
    INTERSECT(
        FILTER(
            DISTINCT (Financial_Combined[Job No.]);
            CALCULATE ( SUM (Financial_Combined[Amount Paid DKK]))>0
        );
        FILTER (
            DISTINCT (Fees[CaseID]);
            CALCULATE (SUM (Fees[FeeAmountDKK])) > 0
        )
    )
)

     

View solution in original post

15 REPLIES 15

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.