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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
ShiMaria
Frequent Visitor

SUM based on several conditions

 

Hello, 

I have the sample of data below. 

What I need is to display the SUM of NNS per YEAR only for the latest gate:

- if Gate3 exsist in the table for specific project, its values for NNS should be SUMmed

- if there is not yet Gate3, but there is Gate2, its values for NNS should be SUMmed

- if there is only Gate1 yet, than its values for NNS should be SUMmed

 

thank you in advance for the support!
Maria

 

GRM DNESGateNNS YearNNS ValueNNS Year Pure
March 2019DNES-001Gate 1NNS 201910182019
August 2019DNES-001Gate 3NNS 201910452019
July 2019DNES-001Gate 2NNS 201910452019
July 2017DNES-002Gate 1NNS 2019169652019
July 2019DNES-002Gate 3NNS 2019178442019
May 2019DNES-002Gate 2NNS 2019169652019
May 2019DNES-002Gate 2NNS 2019197582019
July 2019DNES-002Gate 3NNS 2019207822019
July 2017DNES-002Gate 1NNS 2019197582019
May 2019DNES-004Gate 1NNS 202017262020
May 2019DNES-004Gate 1NNS 202122222021
May 2019DNES-004Gate 1NNS 202232782022
July 2020DNES-004Gate 2NNS 202144092021
July 2020DNES-004Gate 2NNS 2022116312022
July 2020DNES-004Gate 2NNS 2023231942023
September 2019DNES-003Gate 2NNS 20201519682020
October 2019DNES-003Gate 3NNS 20202141732020
September 2019DNES-003Gate 2NNS 20203087762020
October 2019DNES-003Gate 3NNS 20203536872020
September 2019DNES-003Gate 2NNS 2020926052020
October 2019DNES-003Gate 3NNS 20201063052020
September 2019DNES-003Gate 2NNS 20201209672020
October 2019DNES-003Gate 3NNS 20201726942020
September 2019DNES-003Gate 2NNS 20203505722020
October 2019DNES-003Gate 3NNS 20205187732020
September 2019DNES-003Gate 2NNS 20202168312020
October 2019DNES-003Gate 3NNS 20203021312020
September 2019DNES-003Gate 2NNS 2020971802020
October 2019DNES-003Gate 3NNS 20201049582020
September 2019DNES-003Gate 2NNS 20201160002020
October 2019DNES-003Gate 3NNS 20201571902020
September 2019DNES-003Gate 2NNS 2020769172020
October 2019DNES-003Gate 3NNS 20201020982020
1 ACCEPTED SOLUTION
v-xicai
Community Support
Community Support

Hi @ShiMaria ,

 

You may create calculated column and measure like DAX below .

 

Column:

Gate_Number= RIGHT(Table1[Gate], 1)



Measure:

SUMmed Total =
VAR _MaxGate =
    CALCULATE ( MAX ( Table1[Gate_Number] ), ALLEXCEPT ( Table1, Table1[NNS Year Pure], Table1[DNES] ) )
RETURN
    CALCULATE (
        SUM ( Table1[NNS Value] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[NNS Year Pure], Table1[DNES] ),
            Table1[Gate_Number] = _MaxGate
        )
    )

 

Best Regards,

Amy 

 

Community Support Team _ Amy

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

3 REPLIES 3
v-xicai
Community Support
Community Support

Hi @ShiMaria ,

 

You may create calculated column and measure like DAX below .

 

Column:

Gate_Number= RIGHT(Table1[Gate], 1)



Measure:

SUMmed Total =
VAR _MaxGate =
    CALCULATE ( MAX ( Table1[Gate_Number] ), ALLEXCEPT ( Table1, Table1[NNS Year Pure], Table1[DNES] ) )
RETURN
    CALCULATE (
        SUM ( Table1[NNS Value] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[NNS Year Pure], Table1[DNES] ),
            Table1[Gate_Number] = _MaxGate
        )
    )

 

Best Regards,

Amy 

 

Community Support Team _ Amy

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

@ShiMaria , assuming DNES is the project name, else replace column.

Logic if the count of gate = count of gate 1, do not include

 

//per project , per year
sumx(filter(summarize(Table, Table[DNES], Table[NNS Year Pure], "_1", sum(Table[NNS Value]), "_2", count(Table[Gate]) , "_3", calculate(count(Table[Gate]),Table[Gate] ="Date 1"))
, [_2] <> [_3]),[_1])


//per project
sumx(filter(summarize(Table, Table[DNES], "_1", sum(Table[NNS Value]), "_2", count(Table[Gate]) , "_3", calculate(count(Table[Gate]),Table[Gate] ="Date 1"))
, [_2] <> [_3]),[_1])

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hello @amitchandak , 

DNES column contains the project name/number. 

 

when I apply the formula you proposed, it sum all the gates values. 

though, I would like that it sum only values from the latest gate (per project, per year). 

 

thank you in advance for your help, 

Maria

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.