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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
dpearson_soco
Regular Visitor

DAX Measure - Aggregate values and then sum up results

I have a Ledger that contains quantities and cost. The quantities will be repeated as the cost of those quantities change. I need to pull the quantity for a given time period of the last time that record was transacted on and then be able to roll up those quantities to the a single row or be able to break them down by various dimensions. 

My model will have the Values of Date, Location, Program, sequence and quantity. 

During a period of time I would want to group by Location and Program and find the highest Sequence number and return the Quantity value. Once I have that I would want to Sum up all those Quantities. I just don't know how to write that as a Measure with DAX. 

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

Hi @dpearson_soco ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) You've already created the measure [CurrentQty], let's create a new one.

CurrentQty = 
var MaxSeq = MaxX(f_ActivityLedger, [Sequence])
Var MaxResult = CALCULATE(MaxX(f_ActivityLedger, [Quantity]), FILTER(f_ActivityLedger,f_ActivityLedger[Sequence] = MaxSeq))
Return
MaxResult

//Your measure
New_CurrentQty = 
SUMX(
    SUMMARIZE(
       'f_ActivityLedger',
        'f_ActivityLedger'[Location],
        'f_ActivityLedger'[Program],
        "total",[CurrentQty]
    ),
    [total]
)

 (3) Then the result is as follows.

vtangjiemsft_0-1724052899369.png

Best Regards,

Neeko Tang

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-tangjie-msft
Community Support
Community Support

Hi @dpearson_soco ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) You've already created the measure [CurrentQty], let's create a new one.

CurrentQty = 
var MaxSeq = MaxX(f_ActivityLedger, [Sequence])
Var MaxResult = CALCULATE(MaxX(f_ActivityLedger, [Quantity]), FILTER(f_ActivityLedger,f_ActivityLedger[Sequence] = MaxSeq))
Return
MaxResult

//Your measure
New_CurrentQty = 
SUMX(
    SUMMARIZE(
       'f_ActivityLedger',
        'f_ActivityLedger'[Location],
        'f_ActivityLedger'[Program],
        "total",[CurrentQty]
    ),
    [total]
)

 (3) Then the result is as follows.

vtangjiemsft_0-1724052899369.png

Best Regards,

Neeko Tang

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

dpearson_soco
Regular Visitor

Here is some sample data of two programs at different locations for a single month:

Posting DateQuantityProgramSequenceLocation
4/1/20245DVMENV2345649250DN
4/1/20245DVMENV2345920750DN
4/1/202411DVMENV2345715050DN
4/1/202412DVMENV2345920800DN
4/1/202413DVMENV2345693750DN
4/1/202425DVMENV2345920300DN
4/1/202426DVMENV2345692550DN
4/1/202430DVMENV2345649150DN
4/1/202430DVMENV2345693850DN
4/1/202434DVMENV2345714950DN
4/1/202415GEPNAV2345898250GC
4/1/202415GEPNAV2345898350GC
4/1/2024120GEPNAV2345111750GC
4/1/2024240GEPNAV2345904050GC
4/1/2024240GEPNAV2345904450GC
4/1/2024240GEPNAV2345905550GC
4/1/2024300GEPNAV2345906150GC


The measure should produce the quantity as below:

Posting DateProgramQuantityLocation
4/1/2024DVMENV23   34DN
4/1/2024GEPNAV23   300GC


I would also want the measure to be able to roll up and say I have a quantity of 334 for 4/1/2024

I had written this measure which seems to work when I have the data filtered by program and location, but it won't return the sum of the quantity, it will just give me the quantity for the highest sequenced record in the data set:
CurrentQty:=
var MaxSeq = MaxX(f_ActivityLedger, [Sequence])
Var MaxResult = CALCULATE(MaxX(f_ActivityLedger, [SumCurrentQty]), FILTER(f_ActivityLedger,f_ActivityLedger[Sequence] = MaxSeq))
Return
MaxResult

SachinNandanwar
Continued Contributor
Continued Contributor

Please post some sample data..It is very difficult to decipher your expalination to come up with a solution for the problem.



Regards,
Sachin
Check out my Blog

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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