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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
jvrnicfi
Regular Visitor

How to calculate distinct sum with filter

Hi there, newbie questons

I have flat datatable (800 thousand rows)

I want the sum DISTINCT PLACE,WRKNR,WRKROW,MECHANIC WHERE SOURCE = WORKORDER

 

kuva.png

 

something like this:
SELECT DISTINCT PLACE,WRKNR,WRKROW,MECHANIC
CALCULATE SUM(TPOH * TPOPROS / 100)
WHERE SOURCE is WORKORDER

 

But how?

 

 

8 REPLIES 8
tamerj1
Super User
Super User

Hi @jvrnicfi 

Please try

TPO hours =
SUMX (
    FILTER ( 'Table', 'Table'[SOURCE] = "WORKORDER" ),
    'Table'[TPOH] * 'Table'[TPOPROS] / 100
)

Thank you for your answer, solution is correct. Result is same that my own answer example.

However i misleading my queston by my own answer. Thats why i change the picture to clarify my queston.

Main problem is how to calculate with distinct columns (there is many lines that must be ignored)

Hi @jvrnicfi 
Please try

TPO hours =
SUMX (
    SUMMARIZE (
        FILTER ( 'Table', 'Table'[SOURCE] = "WORKORDER" ),
        'Table'[WRKNR],
        'Table'[WRKROW],
        "@TPOH", SUMX ( TOPN ( 1, 'Table', 'Table'[PARTSROW], ASC ), 'Table'[TPOH] ),
        "@TPOPROS", SUMX ( TOPN ( 1, 'Table', 'Table'[PARTSROW], ASC ), 'Table'[TPOPROS] )
    ),
    [@TPOH] * [@TPOPROS] / 100
)
devanshi
Helper V
Helper V

Total = [TPOH] * [TPOPROS]
CALCULATE(SUM([Total]), FILTER('TableName', DISTINCT([Source]) = "WORKOREDER"))

Thank you for your answer, solution is correct. Result is same that my own answer example. 

I do the same focus as I did for "tamerj1"

However i misleading my queston by my own answer. Thats why i change the picture to clarify my queston.

Main problem is how to calculate with distinct columns (there is many lines that must be ignored)

Try this once,
DistinctSum = CALCULATE( SUM('Table'[TPOH] * 'Table'[TPOPROS] / 100),
'Table'[SOURCE] = "WORKORDER",
ALLEXCEPT('Table', 'Table'[PLACE], 'Table'[WRKNR], 'Table'[WRKROW], 'Table'[MECHANIC]) )

some_bih
Super User
Super User

Hi @jvrnicfi for sum two columns and product betwen them you just need measure like Sum Measure. In visual select wanted column. I hope this help
Sum Measure =

SUMX (

        FILTER ( WORKORDER, WORKORDER[SOURCE] = "WORKORDER" ),

WORKORDER[TPOH] * WORKORDER[TPOPROS]

)





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Thank you for your answer, solution is correct. Result is same that my own answer example. 

I do the same focus as I did for "tamerj1"

However i misleading my queston by my own answer. Thats why i change the picture to clarify my queston.

Main problem is how to calculate with distinct columns (there is many lines that must be ignored)

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.