Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hello everyone,
I have the following problem and haven't found a way to solve the "problem".
I have a matrix that receives a customer number via a Scliver MultiSelect. Based on these two customer numbers, the same products should now be compared based on the percentage and marked as over or underrated.
my matrix has the following structure "row Assetklasse;WKN column Portfolio Values Percentage;AssetDescription"
One of this not working scripts:
PROD1 =
VAR SelectedPortfolios = VALUES(PositionData[Portfolio])
VAR SelectedCount = COUNTROWS(SelectedPortfolios)
VAR Portfolio1 =
IF(
SelectedCount = 2,
FIRSTNONBLANK(SelectedPortfolios, PositionData[Portfolio])
)
VAR Portfolio2 =
IF(
SelectedCount = 2,
LASTNONBLANK(SelectedPortfolios, PositionData[Portfolio])
)
VAR Portfolio1Aggregated =
SUMMARIZE(
FILTER(
PositionData,
PositionData[Portfolio] = Portfolio1
),
PositionData[AssetName],
"Portfolio1Percentage", MAX(PositionData[POS_PORTF_PERCENTAGE])
)
VAR Portfolio2Aggregated =
SUMMARIZE(
FILTER(
PositionData,
PositionData[Portfolio] = Portfolio2
),
PositionData[AssetName],
"Portfolio2Percentage", MAX(PositionData[POS_PORTF_PERCENTAGE])
)
VAR CommonAssetNames =
INTERSECT(
SELECTCOLUMNS(Portfolio1Aggregated, "AssetName", PositionData[AssetName]),
SELECTCOLUMNS(Portfolio2Aggregated, "AssetName", PositionData[AssetName])
)
VAR DifferencesTable =
ADDCOLUMNS(
CommonAssetNames,
"Difference",
CALCULATE(
MAXX(
FILTER(Portfolio1Aggregated, PositionData[AssetName] = [AssetName]),
[Portfolio1Percentage]
) -
MAXX(
FILTER(Portfolio2Aggregated, PositionData[AssetName] = [AssetName]),
[Portfolio2Percentage]
)
)
)
VAR AverageDifference =
AVERAGEX(DifferencesTable, [Difference])
RETURN
IF(
SelectedCount = 2,
AverageDifference,
BLANK() )
good morning and thanks for your answer!
There are still some errors in
"Portfolio1Aggregated / AssetName" could not be found and "Portfolio1Percentage" also could not be found / wrong type. But arg had to ref to an table - did not see or get ehat is the issue
You can try the following DAX expression:
Diff_Percentage =
VAR SelectedPortfolios = VALUES(PositionData[Portfolio])
VAR SelectedCount = COUNTROWS(SelectedPortfolios)
VAR Portfolio1 =
IF(
SelectedCount = 2,
FIRSTNONBLANK(SelectedPortfolios, PositionData[Portfolio])
)
VAR Portfolio2 =
IF(
SelectedCount = 2,
LASTNONBLANK(SelectedPortfolios, PositionData[Portfolio])
)
VAR Portfolio1Data =
FILTER(
PositionData,
PositionData[Portfolio] = Portfolio1
)
VAR Portfolio2Data =
FILTER(
PositionData,
PositionData[Portfolio] = Portfolio2
)
VAR Portfolio1Aggregated =
SUMMARIZE(
Portfolio1Data,
PositionData[AssetName],
"Portfolio1Percentage", MAX(PositionData[POS_PORTF_PERCENTAGE])
)
VAR Portfolio2Aggregated =
SUMMARIZE(
Portfolio2Data,
PositionData[AssetName],
"Portfolio2Percentage", MAX(PositionData[POS_PORTF_PERCENTAGE])
)
VAR CommonAssets =
INTERSECT(
SELECTCOLUMNS(Portfolio1Aggregated, "AssetName", PositionData[AssetName]),
SELECTCOLUMNS(Portfolio2Aggregated, "AssetName", PositionData[AssetName])
)
VAR DifferenceTable =
ADDCOLUMNS(
CommonAssets,
"Difference",
VAR Portfolio1Percent = LOOKUPVALUE([Portfolio1Percentage], Portfolio1Aggregated[AssetName], [AssetName])
VAR Portfolio2Percent = LOOKUPVALUE([Portfolio2Percentage], Portfolio2Aggregated[AssetName], [AssetName])
RETURN Portfolio1Percent - Portfolio2Percent
)
VAR AverageDifference =
AVERAGEX(DifferenceTable, [Difference])
RETURN
IF(
SelectedCount = 2,
AverageDifference,
BLANK()
)
Best Regards
hackcrr
If I have answered your question, please mark my reply as solution and kudos to this post, thank you!
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
111 | |
93 | |
88 | |
35 | |
35 |
User | Count |
---|---|
154 | |
101 | |
80 | |
63 | |
54 |