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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
mina97
Helper III
Helper III

count the number of orders

i have the following data

orderstauts
216submited
216accepted
217submited
217resumited
217accepted

i need to count the number of orders that got accepted without being reaplied so in this case it should give one order 

please help and thank you 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @mina97 ,

I created a sample pbix file(see the attachment), please check if that is what you want.

Flag = 
VAR _tab1 =
    CALCULATETABLE (
        VALUES ( 'Table'[order] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[stauts] = "accepted" )
    )
VAR _tab2 =
    CALCULATETABLE (
        VALUES ( 'Table'[order] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[order]
                IN _tab1
                    && 'Table'[stauts] = "resumited"
        )
    )
VAR _tab =
    EXCEPT ( _tab1, _tab2 )
RETURN
    IF ( SELECTEDVALUE ( 'Table'[order] ) IN _tab, 1, 0 )
Number of orders = SUMX(VALUES('Table'[order]),[Flag])

vyiruanmsft_0-1698406038963.png

Best Regards

View solution in original post

13 REPLIES 13
mina97
Helper III
Helper III

i used the same data as you it did NOT 😐 

Hi, @mina97 

 

final =
var a = DISTINCTCOUNT('status'[order])
var b = CALCULATE(DISTINCTCOUNT('status'[order]),'status'[stauts]="resumited")
return
a-b
 

Dangar332_0-1698034731840.png

For download .pbix click HERE 

 

okay thank you for trying some one else will help as i wish hopfully 

Anonymous
Not applicable

Hi @mina97 ,

I created a sample pbix file(see the attachment), please check if that is what you want.

Flag = 
VAR _tab1 =
    CALCULATETABLE (
        VALUES ( 'Table'[order] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[stauts] = "accepted" )
    )
VAR _tab2 =
    CALCULATETABLE (
        VALUES ( 'Table'[order] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[order]
                IN _tab1
                    && 'Table'[stauts] = "resumited"
        )
    )
VAR _tab =
    EXCEPT ( _tab1, _tab2 )
RETURN
    IF ( SELECTEDVALUE ( 'Table'[order] ) IN _tab, 1, 0 )
Number of orders = SUMX(VALUES('Table'[order]),[Flag])

vyiruanmsft_0-1698406038963.png

Best Regards

you are missing the point 🙂 if i wanted this output i would have done it myself 🙂 

mina97
Helper III
Helper III

wrong it gives 0 😞

Hi, @mina97 

It give 1 as a output for code which I provide .

For above data it give 1 as a output 

 

 

Dangar332
Super User
Super User

Hi, @mina97 

try below just adjust your table aand column name 

final =
var a = DISTINCTCOUNT('practice'[order])
var b = CALCULATE(DISTINCTCOUNT('practice'[order]),practice[status]="resumited")
return a-b
 
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. and don't forget to give kudos
mina97
Helper III
Helper III

sorry but the output is wrong ..... it deleted the resubmitted row but it still counted the order as accepted from the first time ... the out put is = 4 where it should be 1 

mina97
Helper III
Helper III

Hi, I am a bit busy these days. I will reply ASAP. 

 

 

Thanks 


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


rubayatyasmin
Super User
Super User

Hi, @mina97 

 

I tried to solve this. here is the output. 

 

rubayatyasmin_0-1697626647624.png

 

AcceptedOrdersWithoutResubmit = 
CALCULATE(
    COUNTROWS('Table'),
    FILTER(
        'Table',
        'Table'[stauts] = "accepted" &&
        NOT (
            CALCULATE(
                COUNTROWS('Table'),
                FILTER(
                    'Table',
                    'Table'[order] = EARLIER('Table'[order]) &&
                    'Table'[stauts] = "resumited"
                )
            ) > 0
        )
    )
)

 

rubayatyasmin_0-1689517080227.png

 


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


hey i am really happy with the code BUT i need it to count the distict number of orders 😞

 

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.