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
RafaelPinto
Regular Visitor

How can I sum a formula where other columns are the minimum

Hi, this is my first time asking here, I'm doing this report for my job so any help is well appreciated. 

I created a metric with Calculate that sums a formula if the value of a column (numkar) is the maximum for each product (numers 02190,02191,....).

 

To-CosCom = CALCULATE(
SUMX(fa_kardex,
IF(LEFT(fa_kardex[tipkar],1)="C",
fa_kardex[stkalm]*fa_kardex[stkfra]+fa_kardex[stkalm_m]+fa_kardex[qtypro]*fa_kardex[stkfra]+fa_kardex[qtypro_m],
fa_kardex[stkalm]*fa_kardex[stkfra]+fa_kardex[stkalm_m]-fa_kardex[qtypro]*fa_kardex[stkfra]-fa_kardex[qtypro_m])
*fa_kardex[coscom]/fa_kardex[stkfra]),
fa_kardex[numkar]= MAX(fa_kardex[numkar]))

 

It's working well for the products but when I want to sum these values for a category of products (in this case Laboratory, like ABBOT NUTRITIONAL) it gives me the minimum value of all the products from the category, not the sum, which is understandable because of the CALCULATE filter. 

RafaelPinto_0-1640711212887.png

 

 

I want to know how can I make that it sums the values and only apply the filter to the products and not to the categories, so I can sum the group.

 

These are my tables used where many products (fa_productos[codpro]) belong to one laboratory (fa_laboratorios[Laboratorio]) and fa_kardex is the transaction table with many records for each product (thats why I used a filter in the CALCULATE that gives me the maximum transaction code = the latest).

RafaelPinto_1-1640711212898.png

 

 

2 REPLIES 2
Anonymous
Not applicable

Hi  @RafaelPinto ,

I created some data:

vyangliumsft_0-1641282690345.png

Here are the steps you can follow:

1. Create measure.

Flag =
IF(
    ISINSCOPE('Table'[group])&&NOT(ISINSCOPE('Table'[group1])),SUMX('Table',[To-CosCom]),[To-CosCom])

2. Result:

vyangliumsft_1-1641282690353.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

MFelix
Super User
Super User

Hi @RafaelPinto ,

 

Try to change you calculation to:

 

To-CosCom =
CALCULATE (
    SUMX (
        fa_kardex,
        IF (
            LEFT ( fa_kardex[tipkar], 1 ) = "C",
            fa_kardex[stkalm] * fa_kardex[stkfra] + fa_kardex[stkalm_m] + fa_kardex[qtypro] * fa_kardex[stkfra] + fa_kardex[qtypro_m],
            fa_kardex[stkalm] * fa_kardex[stkfra] + fa_kardex[stkalm_m] - fa_kardex[qtypro] * fa_kardex[stkfra] - fa_kardex[qtypro_m]
        ) * fa_kardex[coscom] / fa_kardex[stkfra]
    ),
    fa_kardex[numkar] in VALUES( fa_kardex[numkar] )
)

I have replaced the MAX by a VALUES syntax this means that at a level of the product it will consider one product but at the level of the category will consider all products that are within that categorie


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



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.

Top Solution Authors