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
rishabjain237
Helper I
Helper I

How to count rows based on 2 conditions

Hi community,

I want to the count of unique invoices in a invoice columns

Invoice eg:

2023/Q3/141

2023/Q3/143

But there is a catch,

If the invoice numbers are like,

2023/Q3/145/1

2023/Q3/145/2

These should be counted as one as well.

Need some help.

Thanks and regards,

Rishab jain

 

@parry2k Thanks for helping me with 3 rolling averages formula. 

3 ACCEPTED SOLUTIONS
rishabjain237
Helper I
Helper I

@Greg_Deckler 

Hi,

Thank you for a quick response!

I have tried this but it will not take 2023/Q3/251/1

2023/Q3/251/2 has single count. 

View solution in original post

Data-estDog
Resolver II
Resolver II

so both formats exist?

InvoiceNumber = 2023/Q3/145

 

Is this a sub invoice? 2023/Q3/145/2 with the extra "/2"

 

If you want the following to return a distinct count of 1.....

2023/Q3/145/1

2023/Q3/145/2

2023/Q3/145/3

2023/Q3/145/4

2023/Q3/145/5

 

DistinctCount should work. But you need to add new column that trims the InvoiceNumber down to the actual Invoice number (lets call it RootInvoiceNumber) to run the distinct count on. Example:

InvoiceNumber , RootInvoiceNumber
2023/Q3/145/1 , 2023/Q3/145
2023/Q3/145/2 , 2023/Q3/145
2023/Q3/145/3 , 2023/Q3/145
2023/Q3/145/4 , 2023/Q3/145
2023/Q3/145/5 , 2023/Q3/145

View solution in original post

DistinctInvoices =
    COUNTROWS(
    SUMMARIZE(
        ADDCOLUMNS(
            'Dim Invoice',
            "RootInvoice", MID('Dim Invoice'[InvoiceID], 1, 11)
        ),
        [RootInvoice]
    )
)
 
Measure are calculated point in time, so If you are going to use it a lot, Might be better to invest in a new column. YOu can always hide it from the model.

View solution in original post

6 REPLIES 6
Data-estDog
Resolver II
Resolver II

so both formats exist?

InvoiceNumber = 2023/Q3/145

 

Is this a sub invoice? 2023/Q3/145/2 with the extra "/2"

 

If you want the following to return a distinct count of 1.....

2023/Q3/145/1

2023/Q3/145/2

2023/Q3/145/3

2023/Q3/145/4

2023/Q3/145/5

 

DistinctCount should work. But you need to add new column that trims the InvoiceNumber down to the actual Invoice number (lets call it RootInvoiceNumber) to run the distinct count on. Example:

InvoiceNumber , RootInvoiceNumber
2023/Q3/145/1 , 2023/Q3/145
2023/Q3/145/2 , 2023/Q3/145
2023/Q3/145/3 , 2023/Q3/145
2023/Q3/145/4 , 2023/Q3/145
2023/Q3/145/5 , 2023/Q3/145

@Greg_Deckler 

Any dax measure possible without creating a new column???

DistinctInvoices =
    COUNTROWS(
    SUMMARIZE(
        ADDCOLUMNS(
            'Dim Invoice',
            "RootInvoice", MID('Dim Invoice'[InvoiceID], 1, 11)
        ),
        [RootInvoice]
    )
)
 
Measure are calculated point in time, so If you are going to use it a lot, Might be better to invest in a new column. YOu can always hide it from the model.

@Data-estDog 

After you suggested to create a new column..... I open power query and used display 0 or 1 if we have certain condition and then used that column to set a condition for split based of delimiter.  Thank you for your help

rishabjain237
Helper I
Helper I

@Greg_Deckler 

Hi,

Thank you for a quick response!

I have tried this but it will not take 2023/Q3/251/1

2023/Q3/251/2 has single count. 

Greg_Deckler
Super User
Super User

@rishabjain237 Seems like DISTINCTCOUNT or COUNTROWS(DISTINCT(SELECTCOLUMNS( ... ) ) ) should work for this.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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.