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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
ArulBhargavR
Frequent Visitor

Return the number of instance a boolean value is repeating per category

Hi, I have sales data with invoice date, document number and if the invoice is outstanding, I would want to return the instance number of the outstanding invoice for each customer in a new coulmn using DAX. I have attached the data sample and expected result

 

Sample Data : 

 

ArulBhargavR_0-1713950088949.png

 

Result :

 

ArulBhargavR_1-1713950141598.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @ArulBhargavR,

So you mean you only want the first match condition record return 1 and other records return 0? If that is the case , you can try to use the following measure formula and I add variable and condition to exclude not match scenarios:

Invoice Count =
VAR currDate =
    MAX ( Calendar[Date] )
VAR _prevCount =
    CALCULATE (
        COUNT ( Invoice[posting date] ),
        FILTER (
            ALLSELECTED ( Invoice ),
            [posting date] < currDate
                && [outstanding invoice] = "Yes"
        ),
        VALUES ( Invoice[customer] )
    )
RETURN
    IF (
        _prevCount = 0,
        CALCULATE (
            COUNT ( Invoice[document number] ),
            FILTER (
                ALLSELECTED ( Invoice ),
                [posting date] <= currDate
                    && [outstanding invoice] = "Yes"
            ),
            VALUES ( Invoice[customer] )
        )
    ) + 0

Regards,

Xiaoxin Sheng

View solution in original post

3 REPLIES 3
ArulBhargavR
Frequent Visitor

Hi @Anonymous, 

 

Thank you for showing intrest, I have tried the solution presented earlier..after adding customer to the filter function, I have been able to get the total count of "Yes" for said category.

 

however, I want to identify the first instance of "Yes" for each customer based on the earliest date.

 

Anonymous
Not applicable

Hi @ArulBhargavR,

So you mean you only want the first match condition record return 1 and other records return 0? If that is the case , you can try to use the following measure formula and I add variable and condition to exclude not match scenarios:

Invoice Count =
VAR currDate =
    MAX ( Calendar[Date] )
VAR _prevCount =
    CALCULATE (
        COUNT ( Invoice[posting date] ),
        FILTER (
            ALLSELECTED ( Invoice ),
            [posting date] < currDate
                && [outstanding invoice] = "Yes"
        ),
        VALUES ( Invoice[customer] )
    )
RETURN
    IF (
        _prevCount = 0,
        CALCULATE (
            COUNT ( Invoice[document number] ),
            FILTER (
                ALLSELECTED ( Invoice ),
                [posting date] <= currDate
                    && [outstanding invoice] = "Yes"
            ),
            VALUES ( Invoice[customer] )
        )
    ) + 0

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

HI @ArulBhargavR,

You can use the following measure formula to get the outstanding invoice count based on 'customer' and 'posting date' group:

Invoice Count =
VAR currDate =
    MAX ( Calendar[Date] )
RETURN
    CALCULATE (
        COUNT ( Invoice[document number] ),
        FILTER (
            ALLSELECTED ( Invoice ),
            [posting date] <= currDate
                && [outstanding invoice] = "Yes"
        ),
        VALUES ( Invoice[customer] )
    )+0

Regards,
Xiaoxin Sheng

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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