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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

sum only some row in a column

Hi,

i need to sum a value column by an if condition like this

 

That's my DB example

image.png

 

I need to sum "Valore" column only if "ITEMID" & "VENDACCOUNT" (my key) have blank "FP Fornitore" only while there is at least 1 row that isn't blank.

Expected result: € 3630

 

So, if my "ITEMID" & "VENDACCOUNT" have an "FP Fornitore" i need the sum the rest

If my "ITEMID" & "VENDACCOUNT" don't have at least one row in "FP Fornitore" i will not sum

Another example:
image.png

Excepted result: 0

DB doesn't have any row with "FP Fornitore" by "ITEMID" & "VENDACCOUNT"

Last example:
image.png

Expected result: €1936

Hope that's a good explanation

Thanks!

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Calculate measures

Capture1.JPG

Measure 2 =
VAR disc =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[VENDACCOUNT] ),
        ALLEXCEPT (
            'Table',
            'Table'[ITEMID]
        )
    )
VAR con =
    CONCATENATEX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[ITEMID]
                = MAX ( 'Table'[ITEMID] )
        ),
        [FP fornitore]
    )
RETURN
    IF (
        disc > 1
            && con
                <> BLANK (),
        1
    )

Measure =
CALCULATE (
    SUM ( 'Table'[Valore] ),
    FILTER (
        ALLEXCEPT (
            'Table',
            'Table'[ITEMID]
        ),
        'Table'[FP fornitore]
            = BLANK ()
            && [Measure 2] = 1
    )
)

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Calculate measures

Capture1.JPG

Measure 2 =
VAR disc =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[VENDACCOUNT] ),
        ALLEXCEPT (
            'Table',
            'Table'[ITEMID]
        )
    )
VAR con =
    CONCATENATEX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[ITEMID]
                = MAX ( 'Table'[ITEMID] )
        ),
        [FP fornitore]
    )
RETURN
    IF (
        disc > 1
            && con
                <> BLANK (),
        1
    )

Measure =
CALCULATE (
    SUM ( 'Table'[Valore] ),
    FILTER (
        ALLEXCEPT (
            'Table',
            'Table'[ITEMID]
        ),
        'Table'[FP fornitore]
            = BLANK ()
            && [Measure 2] = 1
    )
)

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

The information you have provided is not making the problem clear to me. Can you please explain with an example.

Appreciate your Kudos.


Please Watch/Like/Share My webinar on Time Intelligence: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...
My Youtube Tips at: https://www.youtube.com/playlist?list=PLPaNVDMhUXGYrm5rm6ME6rjzKGSvT9Jmy

Anonymous
Not applicable

image.png

That's good i think

We bought item AX338 from F*096 and F*061 but we have the contract only with F*061, so the rest are "lost money" 

I need to sum the loss, yellow cells!

Anonymous
Not applicable

I need to see if we bought the same ITEM from different vendor, so i need to sum the value for each 

 

Cause we can buy item A from vendor X and item A from vendor Y, maybe Y vendor has a better contract ( column "FP Fornitore"), so i need to sum the value that we lost with the other vendor X

 

While, if we buy item A only from one seller there is no problem!

 

Hope that's better

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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