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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Claster
Advocate II
Advocate II

Count of bill where bought two or more group of product

Hello. I need to calculate count of bill where bought two or more group of product

 

For example, I filtered two groups, I need to count the number of bill where there are these 2 groups.

result: CountOfBill = 2

 

I tried like this but it's don't work =(

 

CountOfBill =
VAR F1 = IF(ISFILTERED('Sales'[ProductGroup]);FIRSTNONBLANK('Sales'[ProductGroup];TRUE()))
VAR F2 = IF(ISFILTERED('Sales'[ProductGroup]);LASTNONBLANK('Sales'[ProductGroup];TRUE()))
RETURN CALCULATE(DISTINCTCOUNT([BillNumber]);FILTER('Sales';[ProductGroup] = F1 && [ProductGroup] = F2))

Безымянный.png

 

1 ACCEPTED SOLUTION

Hi @Claster,

 

The formula below should work in this scenario. Smiley Happy

CountOfBill = 
VAR countOfSelectedGroup =
    DISTINCTCOUNT ( Sales[ProductGroup] )
RETURN
    COUNTROWS (
        FILTER (
            SUMMARIZE (
                Sales,
                Sales[BillNumber],
                "CountOfGroup", DISTINCTCOUNT ( Sales[ProductGroup] )
            ),
            [CountOfGroup] >= countOfSelectedGroup
        )
    ) + 0

Regards

View solution in original post

5 REPLIES 5
v-ljerr-msft
Microsoft Employee
Microsoft Employee

Hi @Claster,

 

Based on my test, the formula below should work in your scenario. Smiley Happy

CountOfBill =
COUNTROWS (
    FILTER (
        SUMMARIZE (
            Sales,
            Sales[BillNumber],
            "CountOfGroup", DISTINCTCOUNT ( Sales[ProductGroup] )
        ),
        [CountOfGroup] >= 2
    )
)

r3.PNG

 

Regards

Thanks for help, but almost right

If I chose 3 ProductGroup the CountOfBill should be 0 (zero)  because I don't have bill where customer bought 3 group in one bill

 

Безымянный.png

 

 

I think like this

CountOfBill =
VAR ChouseCountGroup = COUNTROWS(VALUES('Sales'[ProductGroup]))
VAR F =

COUNTROWS (

    FILTER(
        SUMMARIZE(
                   'Sales';
                   Sales[BillNumber];
                   "CountOfGroup";DISTINCTCOUNT ( Sales[ProductGroup] ));
         [CountOfGroup] = ChouseCountGroup)
)
RETURN IF(F>0;F;0)

Hi @Claster,

 

The formula below should work in this scenario. Smiley Happy

CountOfBill = 
VAR countOfSelectedGroup =
    DISTINCTCOUNT ( Sales[ProductGroup] )
RETURN
    COUNTROWS (
        FILTER (
            SUMMARIZE (
                Sales,
                Sales[BillNumber],
                "CountOfGroup", DISTINCTCOUNT ( Sales[ProductGroup] )
            ),
            [CountOfGroup] >= countOfSelectedGroup
        )
    ) + 0

Regards

Thank you so much !

Great to help! Smiley Happy

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.