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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

How to create a measure to find the last value of group of categories

CategoriesQuantitySort
a541
a762
a83
a74
a45
b21
b62
b683
b4544
b975
b26
c91
c52
c43
c74
c545

 

I have a data set that look like above and I want to create a measure calculation to find the last value of Quantity column by grouping with Categories column.

 

I c ould create a new table using the following dax measure, but I want to create a measure not a table. 

 

Table New = SUMMARIZE(
	Table,Table[Categories],
	"Last Value",
	CALCULATE(SUM(Table[Quantity]),
		FILTER(Table,Table[Sort]=Max(Table[Sort]))
	)
	)

 


Could anyone please help me to use this logic and create a measure rather than calculated table. 

1 ACCEPTED SOLUTION
FrankAT
Community Champion
Community Champion

Hi @Anonymous 

you can do it like this:

 

27-06-_2021_00-40-33.png

 

Last Value =
CALCULATE (
    MAX ( 'Table'[Quantity] ),
    FILTER (
        ALLEXCEPT ( 'Table', 'Table'[Categories] ),
        'Table'[Sort] = MAX ( 'Table'[Sort] )
    )
)

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

View solution in original post

4 REPLIES 4
FrankAT
Community Champion
Community Champion

Hi @Anonymous 

you can do it like this:

 

27-06-_2021_00-40-33.png

 

Last Value =
CALCULATE (
    MAX ( 'Table'[Quantity] ),
    FILTER (
        ALLEXCEPT ( 'Table', 'Table'[Categories] ),
        'Table'[Sort] = MAX ( 'Table'[Sort] )
    )
)

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

aj1973
Community Champion
Community Champion

Hi @Anonymous or try this

aj1973_0-1624720525849.png

 

Last value =
var _Category = SELECTEDVALUE(Sheet2[Categories])
var _LastSort = MAX(Sheet2[Sort])
return
CALCULATE(SUM(Sheet2[Quantity]) , Sheet2[Categories] = _Category , Sheet2[Sort] = _LastSort)

 

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Jihwan_Kim
Super User
Super User

 

Picture1.png

 

https://www.dropbox.com/s/859um2z34didt66/surafel.pbix?dl=0 

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
parry2k
Super User
Super User

@Anonymous try this measure

 

Top Qty = CALCULATE ( SUM ( Cat[Quantity] ), TOPN ( 1,  ALLSELECTED (  Cat[Sort] ), CALCULATE ( MAX ( Cat[Sort] ) ), DESC ) ) 

 

Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors