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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
lkhall
Helper I
Helper I

Total By Last Records in a group

Good morning, 

 

I have a table that for each "Product Name" with a "Product Category" = 'Neuromodulator' I need to identify the MAX(fact inventory pk) and return the associated "Cumulative Stock" grouped by "Center Name". I have a measure that will return this correctly for each individual product in a center but now I want to just return the sum of all the records returned by center. 

 

lkhall_0-1710253011276.png

 

so in the case of the above image I now just want to return 1 record of 600. Below I have provided the measure that I am using to get the last record and its assoicated stock levels by Product Name. Any input would be greatly appreciated. 

 

Current On Hand = 

var _id = CALCULATE(
            MAX(FactInventory[fact inventory pk]),
            REMOVEFILTERS(FactInventory[Is Current Audit])
        )

return 

CALCULATE(
    SUM(FactInventory[Cumulative Stock]),
    FactInventory[fact inventory pk] = _id,
    REMOVEFILTERS(FactInventory[Is Current Audit])
)

 

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

Hi @lkhall 

 

Maybe you can use summarize() function to create a virtual tables in new measure and use the sumx() to get the sum.

Here for your reference:

vzhengdxumsft_0-1710296136281.pngvzhengdxumsft_1-1710296143620.png

Then add a new measure:

Measure 2 = 
	VAR _virtualtable = SUMMARIZE(
		ALLSELECTED('Table'),
		'Table'[Name],
		"Values", [Measure]
	)
	RETURN
		SUMX(
			_virtualtable,
			[Measure]
		)

The result is as follow:

vzhengdxumsft_2-1710296234665.png

 

Best Regards

Zhengdong Xu
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

1 REPLY 1
v-zhengdxu-msft
Community Support
Community Support

Hi @lkhall 

 

Maybe you can use summarize() function to create a virtual tables in new measure and use the sumx() to get the sum.

Here for your reference:

vzhengdxumsft_0-1710296136281.pngvzhengdxumsft_1-1710296143620.png

Then add a new measure:

Measure 2 = 
	VAR _virtualtable = SUMMARIZE(
		ALLSELECTED('Table'),
		'Table'[Name],
		"Values", [Measure]
	)
	RETURN
		SUMX(
			_virtualtable,
			[Measure]
		)

The result is as follow:

vzhengdxumsft_2-1710296234665.png

 

Best Regards

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

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors