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
oanu
Regular Visitor

Get value of partner ticker

Hi all,

I would like to get the latest value of “Counterpart” ticker (aka “Peer”) of the selected ticker. Below are the details:

 

Model has 4 tables: Dim_Assets contains some metadata for tickers; Peers table specify which Ticker has which Peer (Peer is also Ticker Code from Dim_Assets); Historical Data is obvious.

oanu_0-1701082371745.png

 

All Ticker Codes have historical data. Several Ticker code could have the same Peer.

 

I have some measures which work just fine:

Current Value = CALCULATE(SUM('Fact_Historical_Data'[Value]),LASTDATE('Fact_Historical_Data'[Period]))

Date of Current Value = CALCULATE(SUM('Fact_Historical_Data'[Period]),LASTDATE('Fact_Historical_Data'[Period]))

Peer Existence Check = 
VAR CurrentTicker = SELECTEDVALUE(Dim_Assets[Ticker Code])
RETURN LOOKUPVALUE(Peers[Peer Code], Peers[Ticker Code], CurrentTicker, Blank())

Peer Latest Period = 
VAR CurrentTicker = SELECTEDVALUE(Dim_Assets[Ticker Code])
VAR PeerTicker = LOOKUPVALUE(Peers[Peer Code], Peers[Ticker Code], CurrentTicker, BLANK())
RETURN
IF(NOT ISBLANK(PeerTicker),
CALCULATE(MAX(Fact_Historical_Data[Period]), Fact_Historical_Data[Ticker Code] = PeerTicker, ALL(Fact_Historical_Data)),
BLANK()
)

However, the measure to get the value of Peer always returns blank:

Peer Current Value = 
VAR LatestPeriod = CALCULATE(MAX(Fact_Historical_Data[Period]), ALL(Fact_Historical_Data))
VAR CurrentTicker = SELECTEDVALUE(Dim_Assets[Ticker Code])
VAR PeerTicker = LOOKUPVALUE(Peers[Peer Code], Peers[Ticker Code], CurrentTicker, BLANK())
RETURN
IF(ISBLANK(PeerTicker), BLANK(),
    CALCULATE(
        SUM(Fact_Historical_Data[Value]),
        Fact_Historical_Data[Ticker Code] = PeerTicker,
        Fact_Historical_Data[Period] = LatestPeriod
    )
)

Could you pls give a hint here.

regards,

Alex

 

3 REPLIES 3
oanu
Regular Visitor

Hi all,

 

Thank you for support. I decided to move column "Peer Code" to Dim_Assets Table and also adjusted the "Peer Current Value" measure as follows:

Peer Current Value = 
VAR LatestPeriod = LASTDATE('Fact_Historical_Data'[Period])
VAR PeerTicker = SELECTEDVALUE(Dim_Assets[Peer Code])
RETURN
IF(
    ISBLANK(PeerTicker),
    BLANK(),
    CALCULATE(
        SUM(Fact_Historical_Data[Value]),
        All(Fact_Historical_Data),
        Fact_Historical_Data[Ticker Code] = PeerTicker,
        Fact_Historical_Data[Period] = LatestPeriod
    )
)

So I added filter "All(Fact_Historical_Data)" and now it works.

regards,

Alex

WinterMist
Impactful Individual
Impactful Individual

@oanu 

 

I'm wondering if this has to do with the data.

What happens if you remove the Alternate_Result parameter from VAR PeerTicker and simply return the VAR PeerTicker?

 

 

 

Your ALTERNATE RESULT = BLANK().

 

WinterMist_2-1701116970690.png

 

 

WinterMist_3-1701117188939.png

 

 

 

If it throws an error, that would tell me that more than one value is getting returned.

(And if you're getting more than one value, that makes sense why the entire measure is returning BLANK all the time.)

 

Regards,

Nathan

 

 

WinterMist
Impactful Individual
Impactful Individual

@oanu 

 

Is there any chance you can upload the PBIX to Google Drive and share the link in this thread?

 

Regards,

Nathan

 

P.S.  If not, would it be possible to create a PBIX with a small amount of mock data that should work?

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

Top Solution Authors