Power BI - weighted average yield across 2 tables of a given date
I would like to calculate average yield between two relation tables of a given date
Table1 Table2
+-------------------------------+ +-------------------------------+
| ID TradeDate Amount | | ID TradeDate Yield |
+-------------------------------+ +-------------------------------+
| 1 2018/11/30 100 | | 1 2018/11/8 2.2% |
| 1 2018/11/8 101 | | 1 2018/8/8 2.1% |
| 1 2018/10/31 102 | | 1 2018/5/8 2.0% |
| 1 2018/9/30 103 | | 2 2018/9/8 1.7% |
| 2 2018/11/30 200 | | 2 2018/6/8 1.6% |
| 2 2018/10/31 203 | | 2 2018/3/8 1.5% |
| 2 2018/9/30 205 | | 3 2018/10/20 1.7% |
| 3 2018/11/30 300 | | 3 2018/7/20 1.6% |
| 3 2018/10/31 300 | | 3 2018/4/20 1.6% |
| 3 2018/9/30 300 | +-------------------------------+
+-------------------------------+
I create a table named 'DateList' and use slicer to select a specified date.
Screen Shot DateList.
I want to achieve the following result:
as of *11/9/2018*
+-----------------------------------------------------------------+
| ID LastDate Value LatestYieldDate LastYield |
+-----------------------------------------------------------------+
| 1 2018/11/8 101 2018/11/8 2.2% |
| 2 2018/10/31 203 2018/9/8 1.7% |
| 3 2018/10/31 300 2018/10/20 1.7% |
+-----------------------------------------------------------------+
| Total 604 1.7836% |
+-----------------------------------------------------------------+
Currently, I use the following formula to achieve the partial result
Create 2 measures in table1
LastDate =
VAR SlicerDate = MIN(DateList[Date])
VAR MinDiff =
MINX(FILTER(ALL(Table1),Table1[ID] IN VALUES(Table1[ID])),
ABS(SlicerDate - Table1[TradeDate]))
RETURN
MINX(FILTER(ALL(Table1),Table1[ID] IN VALUES(Table1[ID])
&& ABS(SlicerDate - Table1[TradeDate]) = MinDiff),
Table1[TradeDate])
Value = CALCULATE(SUM(Table1[Amount]), FILTER(Table1, Table1[TradeDate] = [LastDate]))
Create 2 measures in table2
LastYieldDate =
VAR SlicerDate = MIN(DateList[Date])
VAR MinDiff =
MINX(FILTER(ALL(Table2),Table2[ID] IN VALUES(Table2[ID])),
ABS(SlicerDate - Table2[TradeDate]))
RETURN
MINX(FILTER(ALL(Table2),Table2[ID] IN VALUES(Table2[ID])
&& ABS(SlicerDate - Table2[TradeDate]) = MinDiff),
Table2[TradeDate])
LastYield = CALCULATE(SUM(Table2[Yield]), FILTER(Table2,
Table2[TradeDate] = [LastYieldDate]))
I have no idea to calculate right average yield between 2 tables
Here is my current result.
Screen Shot Current Result.
powerbi
add a comment |
I would like to calculate average yield between two relation tables of a given date
Table1 Table2
+-------------------------------+ +-------------------------------+
| ID TradeDate Amount | | ID TradeDate Yield |
+-------------------------------+ +-------------------------------+
| 1 2018/11/30 100 | | 1 2018/11/8 2.2% |
| 1 2018/11/8 101 | | 1 2018/8/8 2.1% |
| 1 2018/10/31 102 | | 1 2018/5/8 2.0% |
| 1 2018/9/30 103 | | 2 2018/9/8 1.7% |
| 2 2018/11/30 200 | | 2 2018/6/8 1.6% |
| 2 2018/10/31 203 | | 2 2018/3/8 1.5% |
| 2 2018/9/30 205 | | 3 2018/10/20 1.7% |
| 3 2018/11/30 300 | | 3 2018/7/20 1.6% |
| 3 2018/10/31 300 | | 3 2018/4/20 1.6% |
| 3 2018/9/30 300 | +-------------------------------+
+-------------------------------+
I create a table named 'DateList' and use slicer to select a specified date.
Screen Shot DateList.
I want to achieve the following result:
as of *11/9/2018*
+-----------------------------------------------------------------+
| ID LastDate Value LatestYieldDate LastYield |
+-----------------------------------------------------------------+
| 1 2018/11/8 101 2018/11/8 2.2% |
| 2 2018/10/31 203 2018/9/8 1.7% |
| 3 2018/10/31 300 2018/10/20 1.7% |
+-----------------------------------------------------------------+
| Total 604 1.7836% |
+-----------------------------------------------------------------+
Currently, I use the following formula to achieve the partial result
Create 2 measures in table1
LastDate =
VAR SlicerDate = MIN(DateList[Date])
VAR MinDiff =
MINX(FILTER(ALL(Table1),Table1[ID] IN VALUES(Table1[ID])),
ABS(SlicerDate - Table1[TradeDate]))
RETURN
MINX(FILTER(ALL(Table1),Table1[ID] IN VALUES(Table1[ID])
&& ABS(SlicerDate - Table1[TradeDate]) = MinDiff),
Table1[TradeDate])
Value = CALCULATE(SUM(Table1[Amount]), FILTER(Table1, Table1[TradeDate] = [LastDate]))
Create 2 measures in table2
LastYieldDate =
VAR SlicerDate = MIN(DateList[Date])
VAR MinDiff =
MINX(FILTER(ALL(Table2),Table2[ID] IN VALUES(Table2[ID])),
ABS(SlicerDate - Table2[TradeDate]))
RETURN
MINX(FILTER(ALL(Table2),Table2[ID] IN VALUES(Table2[ID])
&& ABS(SlicerDate - Table2[TradeDate]) = MinDiff),
Table2[TradeDate])
LastYield = CALCULATE(SUM(Table2[Yield]), FILTER(Table2,
Table2[TradeDate] = [LastYieldDate]))
I have no idea to calculate right average yield between 2 tables
Here is my current result.
Screen Shot Current Result.
powerbi
add a comment |
I would like to calculate average yield between two relation tables of a given date
Table1 Table2
+-------------------------------+ +-------------------------------+
| ID TradeDate Amount | | ID TradeDate Yield |
+-------------------------------+ +-------------------------------+
| 1 2018/11/30 100 | | 1 2018/11/8 2.2% |
| 1 2018/11/8 101 | | 1 2018/8/8 2.1% |
| 1 2018/10/31 102 | | 1 2018/5/8 2.0% |
| 1 2018/9/30 103 | | 2 2018/9/8 1.7% |
| 2 2018/11/30 200 | | 2 2018/6/8 1.6% |
| 2 2018/10/31 203 | | 2 2018/3/8 1.5% |
| 2 2018/9/30 205 | | 3 2018/10/20 1.7% |
| 3 2018/11/30 300 | | 3 2018/7/20 1.6% |
| 3 2018/10/31 300 | | 3 2018/4/20 1.6% |
| 3 2018/9/30 300 | +-------------------------------+
+-------------------------------+
I create a table named 'DateList' and use slicer to select a specified date.
Screen Shot DateList.
I want to achieve the following result:
as of *11/9/2018*
+-----------------------------------------------------------------+
| ID LastDate Value LatestYieldDate LastYield |
+-----------------------------------------------------------------+
| 1 2018/11/8 101 2018/11/8 2.2% |
| 2 2018/10/31 203 2018/9/8 1.7% |
| 3 2018/10/31 300 2018/10/20 1.7% |
+-----------------------------------------------------------------+
| Total 604 1.7836% |
+-----------------------------------------------------------------+
Currently, I use the following formula to achieve the partial result
Create 2 measures in table1
LastDate =
VAR SlicerDate = MIN(DateList[Date])
VAR MinDiff =
MINX(FILTER(ALL(Table1),Table1[ID] IN VALUES(Table1[ID])),
ABS(SlicerDate - Table1[TradeDate]))
RETURN
MINX(FILTER(ALL(Table1),Table1[ID] IN VALUES(Table1[ID])
&& ABS(SlicerDate - Table1[TradeDate]) = MinDiff),
Table1[TradeDate])
Value = CALCULATE(SUM(Table1[Amount]), FILTER(Table1, Table1[TradeDate] = [LastDate]))
Create 2 measures in table2
LastYieldDate =
VAR SlicerDate = MIN(DateList[Date])
VAR MinDiff =
MINX(FILTER(ALL(Table2),Table2[ID] IN VALUES(Table2[ID])),
ABS(SlicerDate - Table2[TradeDate]))
RETURN
MINX(FILTER(ALL(Table2),Table2[ID] IN VALUES(Table2[ID])
&& ABS(SlicerDate - Table2[TradeDate]) = MinDiff),
Table2[TradeDate])
LastYield = CALCULATE(SUM(Table2[Yield]), FILTER(Table2,
Table2[TradeDate] = [LastYieldDate]))
I have no idea to calculate right average yield between 2 tables
Here is my current result.
Screen Shot Current Result.
powerbi
I would like to calculate average yield between two relation tables of a given date
Table1 Table2
+-------------------------------+ +-------------------------------+
| ID TradeDate Amount | | ID TradeDate Yield |
+-------------------------------+ +-------------------------------+
| 1 2018/11/30 100 | | 1 2018/11/8 2.2% |
| 1 2018/11/8 101 | | 1 2018/8/8 2.1% |
| 1 2018/10/31 102 | | 1 2018/5/8 2.0% |
| 1 2018/9/30 103 | | 2 2018/9/8 1.7% |
| 2 2018/11/30 200 | | 2 2018/6/8 1.6% |
| 2 2018/10/31 203 | | 2 2018/3/8 1.5% |
| 2 2018/9/30 205 | | 3 2018/10/20 1.7% |
| 3 2018/11/30 300 | | 3 2018/7/20 1.6% |
| 3 2018/10/31 300 | | 3 2018/4/20 1.6% |
| 3 2018/9/30 300 | +-------------------------------+
+-------------------------------+
I create a table named 'DateList' and use slicer to select a specified date.
Screen Shot DateList.
I want to achieve the following result:
as of *11/9/2018*
+-----------------------------------------------------------------+
| ID LastDate Value LatestYieldDate LastYield |
+-----------------------------------------------------------------+
| 1 2018/11/8 101 2018/11/8 2.2% |
| 2 2018/10/31 203 2018/9/8 1.7% |
| 3 2018/10/31 300 2018/10/20 1.7% |
+-----------------------------------------------------------------+
| Total 604 1.7836% |
+-----------------------------------------------------------------+
Currently, I use the following formula to achieve the partial result
Create 2 measures in table1
LastDate =
VAR SlicerDate = MIN(DateList[Date])
VAR MinDiff =
MINX(FILTER(ALL(Table1),Table1[ID] IN VALUES(Table1[ID])),
ABS(SlicerDate - Table1[TradeDate]))
RETURN
MINX(FILTER(ALL(Table1),Table1[ID] IN VALUES(Table1[ID])
&& ABS(SlicerDate - Table1[TradeDate]) = MinDiff),
Table1[TradeDate])
Value = CALCULATE(SUM(Table1[Amount]), FILTER(Table1, Table1[TradeDate] = [LastDate]))
Create 2 measures in table2
LastYieldDate =
VAR SlicerDate = MIN(DateList[Date])
VAR MinDiff =
MINX(FILTER(ALL(Table2),Table2[ID] IN VALUES(Table2[ID])),
ABS(SlicerDate - Table2[TradeDate]))
RETURN
MINX(FILTER(ALL(Table2),Table2[ID] IN VALUES(Table2[ID])
&& ABS(SlicerDate - Table2[TradeDate]) = MinDiff),
Table2[TradeDate])
LastYield = CALCULATE(SUM(Table2[Yield]), FILTER(Table2,
Table2[TradeDate] = [LastYieldDate]))
I have no idea to calculate right average yield between 2 tables
Here is my current result.
Screen Shot Current Result.
powerbi
powerbi
edited Nov 15 '18 at 17:02
user10249172
asked Nov 15 '18 at 13:21
AndyChuAndyChu
185
185
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You'll first need to create a bridge table for the ID
values so you can work with both tables more easily.
IDList = VALUES(Table1[ID])
Now we'll use IDList[ID]
on our visual instead of the ID
from one of the other tables.
The measure we use for the average last yield is a basic sum-product average:
LastYieldAvg =
DIVIDE(
SUMX(IDList, [Value] * [LastYield]),
SUMX(IDList, [Value])
)
Note that when there is only a single ID
value, it simplifies to
[Value] * [LastYield] / [Value] = [LastYield]
Thanks again Alexis. Can i use DAX directly rather than to create a bridge table?
– AndyChu
Nov 16 '18 at 1:08
Hi Alexis, if i have additional column named [company] (such as A, B, C,...) in table 1 & table 2, how can i combine [company] & [ID] in bridge table [IDList]? Thanks
– AndyChu
Nov 16 '18 at 8:16
There are some workarounds for creating relationships on multiple columns.
– Alexis Olson
Nov 16 '18 at 15:58
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320431%2fpower-bi-weighted-average-yield-across-2-tables-of-a-given-date%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You'll first need to create a bridge table for the ID
values so you can work with both tables more easily.
IDList = VALUES(Table1[ID])
Now we'll use IDList[ID]
on our visual instead of the ID
from one of the other tables.
The measure we use for the average last yield is a basic sum-product average:
LastYieldAvg =
DIVIDE(
SUMX(IDList, [Value] * [LastYield]),
SUMX(IDList, [Value])
)
Note that when there is only a single ID
value, it simplifies to
[Value] * [LastYield] / [Value] = [LastYield]
Thanks again Alexis. Can i use DAX directly rather than to create a bridge table?
– AndyChu
Nov 16 '18 at 1:08
Hi Alexis, if i have additional column named [company] (such as A, B, C,...) in table 1 & table 2, how can i combine [company] & [ID] in bridge table [IDList]? Thanks
– AndyChu
Nov 16 '18 at 8:16
There are some workarounds for creating relationships on multiple columns.
– Alexis Olson
Nov 16 '18 at 15:58
add a comment |
You'll first need to create a bridge table for the ID
values so you can work with both tables more easily.
IDList = VALUES(Table1[ID])
Now we'll use IDList[ID]
on our visual instead of the ID
from one of the other tables.
The measure we use for the average last yield is a basic sum-product average:
LastYieldAvg =
DIVIDE(
SUMX(IDList, [Value] * [LastYield]),
SUMX(IDList, [Value])
)
Note that when there is only a single ID
value, it simplifies to
[Value] * [LastYield] / [Value] = [LastYield]
Thanks again Alexis. Can i use DAX directly rather than to create a bridge table?
– AndyChu
Nov 16 '18 at 1:08
Hi Alexis, if i have additional column named [company] (such as A, B, C,...) in table 1 & table 2, how can i combine [company] & [ID] in bridge table [IDList]? Thanks
– AndyChu
Nov 16 '18 at 8:16
There are some workarounds for creating relationships on multiple columns.
– Alexis Olson
Nov 16 '18 at 15:58
add a comment |
You'll first need to create a bridge table for the ID
values so you can work with both tables more easily.
IDList = VALUES(Table1[ID])
Now we'll use IDList[ID]
on our visual instead of the ID
from one of the other tables.
The measure we use for the average last yield is a basic sum-product average:
LastYieldAvg =
DIVIDE(
SUMX(IDList, [Value] * [LastYield]),
SUMX(IDList, [Value])
)
Note that when there is only a single ID
value, it simplifies to
[Value] * [LastYield] / [Value] = [LastYield]
You'll first need to create a bridge table for the ID
values so you can work with both tables more easily.
IDList = VALUES(Table1[ID])
Now we'll use IDList[ID]
on our visual instead of the ID
from one of the other tables.
The measure we use for the average last yield is a basic sum-product average:
LastYieldAvg =
DIVIDE(
SUMX(IDList, [Value] * [LastYield]),
SUMX(IDList, [Value])
)
Note that when there is only a single ID
value, it simplifies to
[Value] * [LastYield] / [Value] = [LastYield]
answered Nov 15 '18 at 16:23
Alexis OlsonAlexis Olson
14.9k21935
14.9k21935
Thanks again Alexis. Can i use DAX directly rather than to create a bridge table?
– AndyChu
Nov 16 '18 at 1:08
Hi Alexis, if i have additional column named [company] (such as A, B, C,...) in table 1 & table 2, how can i combine [company] & [ID] in bridge table [IDList]? Thanks
– AndyChu
Nov 16 '18 at 8:16
There are some workarounds for creating relationships on multiple columns.
– Alexis Olson
Nov 16 '18 at 15:58
add a comment |
Thanks again Alexis. Can i use DAX directly rather than to create a bridge table?
– AndyChu
Nov 16 '18 at 1:08
Hi Alexis, if i have additional column named [company] (such as A, B, C,...) in table 1 & table 2, how can i combine [company] & [ID] in bridge table [IDList]? Thanks
– AndyChu
Nov 16 '18 at 8:16
There are some workarounds for creating relationships on multiple columns.
– Alexis Olson
Nov 16 '18 at 15:58
Thanks again Alexis. Can i use DAX directly rather than to create a bridge table?
– AndyChu
Nov 16 '18 at 1:08
Thanks again Alexis. Can i use DAX directly rather than to create a bridge table?
– AndyChu
Nov 16 '18 at 1:08
Hi Alexis, if i have additional column named [company] (such as A, B, C,...) in table 1 & table 2, how can i combine [company] & [ID] in bridge table [IDList]? Thanks
– AndyChu
Nov 16 '18 at 8:16
Hi Alexis, if i have additional column named [company] (such as A, B, C,...) in table 1 & table 2, how can i combine [company] & [ID] in bridge table [IDList]? Thanks
– AndyChu
Nov 16 '18 at 8:16
There are some workarounds for creating relationships on multiple columns.
– Alexis Olson
Nov 16 '18 at 15:58
There are some workarounds for creating relationships on multiple columns.
– Alexis Olson
Nov 16 '18 at 15:58
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320431%2fpower-bi-weighted-average-yield-across-2-tables-of-a-given-date%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown