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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Invoice-lines

I'm new to PowerBI, so any help would be greatly appreciated! I have attached a table below as an example.

 

Invoice IDInvoice line IDCategoryWanted
11AA
12BA
13AA
14AA
25AA
26BA
27CA
38BNot A
39BNot A
410BNot A
411BNot A
412CNot A
413CNot A

 

I have some invoices which need to be categorized. The "Wanted" column contains an example of the required output.

 

In the table, there are 4 unique invoices (4 unique IDs). An invoice consists of multiple invoice lines (13 unique IDs). For example, Invoice ID 2 contains 3 Invoice lines, with Invoice line ID 5, 6 and 7. For each Invoice ID, I would like to check whether one or multiples rows contain Category "A". If that is the case, the output should be "A", otherwise it should be "Not A". 

 

For example, Invoice ID 1 contains three rows with Category "A", so the wanted output should be "A". Invoice ID 2 contains one row with Category "A", so the output should also be "A". Invoice ID 3 and 4 contain no row with Category "A", so the output should be "Not A".

 

Thanks in advance!

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

@Anonymous 

You can add a calculated column to your table with this code.

Wanted = 
VAR _ACount = 
    CALCULATE(
        COUNTROWS('Table'),
        'Table'[Category]="A"
        ,ALLEXCEPT('Table','Table'[Invoice ID])
    )
RETURN 
    IF ( _ACount > 0, "A", "Not A")

2022-01-19_13-15-29.png

View solution in original post

2 REPLIES 2
jdbuchanan71
Super User
Super User

@Anonymous 

You can add a calculated column to your table with this code.

Wanted = 
VAR _ACount = 
    CALCULATE(
        COUNTROWS('Table'),
        'Table'[Category]="A"
        ,ALLEXCEPT('Table','Table'[Invoice ID])
    )
RETURN 
    IF ( _ACount > 0, "A", "Not A")

2022-01-19_13-15-29.png

Anonymous
Not applicable

It works perfectly. Your help is greatly appreciated, you saved me a lot of work. Thanks a lot!

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.