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
baronraghu_3011
Frequent Visitor

sum of two measure showing incorrect value

Hi All

 

I have two tables 

 

Table 1 with Stock names and the quantity purchased

Table 2 with Last 1 year Historic prices of each stock

 

I have a two measure 

1. Measure 1 - total quantity which is the sum of all the quantites  of the stock

2. Measure 2 - Last Traded Price = This gives the Last trade price of each stock on the last traded date say 13th Jan 2023

 

I want to calculate the portfolio value on the Last Traded Date which should be simply the the sumproduct of quantity i have (measure 1) and the Last traded price (measure 2) for each stock

 

Thanks in Advance

 

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Oh i didnt see your latest reply of thr table please try

 

  • Correct values = if(hasonevalue(table[stockname]),[portfolio measure],sumx(values(table[stockname]),[portfolio measure]))

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hello @baronraghu_3011 can you please share the measures as well as providing a sample of your data would help a lot

HI,

 

table 1 has two columns

Column 1 - stock name

Column 2 - quantity

Measure 1 - Sum( Table1[quantity])

 

Table 2 has tow columns 

Column 1 - Stock Name

Colume 2 - Date

Column 3 -  Daily Stock Price

 

I craeted a two refernce Measure for the

1. Last Trading Date = Today()-2

2. Stock Price = Sum (Table 2[Stock Price])

 

Measure 2 - Last Trading Price = calculate (Stock Price, Filter( Date, Date[Date]= Last Trading Date))

 

For calculating my total Portfolio Value = Measure 1 ( Total Quantity)* Measure 2 ( Last Trading Price) .

 

This I understand maynot give correct value as the quantity is multiplied with all the stock prices. So i believe it must be sum product. But hoe to apply has been my concern.

 

 

 

Anonymous
Not applicable

I think youcan try a sumx measure

 

Sumx(values(table[date]),measure1 * measure 2)

Greg_Deckler
Super User
Super User

@baronraghu_3011 Hard to say with the information provided but, perhaps this is the classic measure totals problem?

 

First, please vote for this idea: https://ideas.powerbi.com/ideas/idea/?ideaid=082203f1-594f-4ba7-ac87-bb91096c742e

This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

Also: https://youtu.be/uXRriTN0cfY
And: https://youtu.be/n4TYhF2ARe8



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi,

 

Thanks for those links. I understand a bit that using Hasonefilter along with SUMX might  turnaround the table the way I want to look but finding it hard to implement.   I have shared  snap of my table below for your refernce. The red circle is my issue which doesnt add up.

sumproduct.PNG

Anonymous
Not applicable

Oh i didnt see your latest reply of thr table please try

 

  • Correct values = if(hasonevalue(table[stockname]),[portfolio measure],sumx(values(table[stockname]),[portfolio measure]))

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!

November Carousel

Fabric Community Update - November 2024

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

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.