Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
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!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
81 | |
79 | |
58 | |
35 | |
34 |
User | Count |
---|---|
99 | |
59 | |
56 | |
46 | |
40 |