Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
filipebodas
Helper I
Helper I

Connect two datasets and retrieve last value

Hello everyone,

I'm doing a dashboard for my investments and I have some doubts on how to relate two tables.

 

One has all the movements I have done in my online broker and the other has 3 columns (Date, Ticker, close_price)

TABLE_1:

DateType_IDTypeMovementProductCostQuantityAmount
24/03/20201ExpenditurePurchaseIWDA43.09143.09
24/03/20201ExpenditureComissionIWDA212
19/04/20201ExpenditurePurchaseEMIM22.06243.12

 

etc...

 

TABLE_2:

DateTickerclose_price
15/02/2020IWDA74.41
15/02/2020EMIM31.38
14/02/2020IWDA74.55
14/02/2020EMIM31.5

 

etc...

 

I want to create a relationship, so I can get the latest close_price for each ticker. Is a M:M relation a problem? The final goal is to see the variation in value in each date for each ticker.

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @filipebodas 

It's possible to get the latest value in another table. According to the Product name of the current row, go to another table to find the value of the latest date of the same product name.

e.g. create the the measure

get the latest close_price = 
VAR _latestDate =
    CALCULATE (
        MAX ( Table2[Date] ),
        FILTER ( ALL ( Table2 ), Table2[Ticker] = MIN ( Table1[Product] ) )
    )
RETURN
    CALCULATE (
        MAX ( Table2[close_price] ),
        FILTER (
            ALL ( Table2 ),
            Table2[Date] = _latestDate
                && Table2[Ticker] = MIN ( Table1[Product] )
        )
    )

 

 

vxiaotang_0-1645172770081.png

vxiaotang_0-1645172956698.png

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-xiaotang
Community Support
Community Support

Hi @filipebodas 

It's possible to get the latest value in another table. According to the Product name of the current row, go to another table to find the value of the latest date of the same product name.

e.g. create the the measure

get the latest close_price = 
VAR _latestDate =
    CALCULATE (
        MAX ( Table2[Date] ),
        FILTER ( ALL ( Table2 ), Table2[Ticker] = MIN ( Table1[Product] ) )
    )
RETURN
    CALCULATE (
        MAX ( Table2[close_price] ),
        FILTER (
            ALL ( Table2 ),
            Table2[Date] = _latestDate
                && Table2[Ticker] = MIN ( Table1[Product] )
        )
    )

 

 

vxiaotang_0-1645172770081.png

vxiaotang_0-1645172956698.png

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

tamerj1
Super User
Super User

Hi @filipebodas 

Many to Many in your case is not a problem but if you have gaps in dates in both tables then most probably you're in trouble. 
Better to connect both through a Date table. If this the only requirement then you can generate a simple calendar table (New Table) using this code:

Date =
VAR MinDate = MIN ( Table1[Date] , Table2[Date] )

VAR MaxDate = MAX ( Table1[Date] , Table2[Date] )

VAR Result = CALENDAR ( MinDate, MaxDate)

RETRUN

Result

 

Then connect both tables to Date table one to many relationships. The rest depend on what visuals you need. 

I do have gaps between tables, but I also have a Calendar Table already created.

At least, I would like a visual to see the global and daily variation of each stock/etf

I don't realy get it. If you don't have gaps in the dates in the dimension table, then whay should look for the nearest date while you have the exact one? Are you sure you don't have missing dates in the dimension table? 
The date table that you need to create in power query is just one column table that will become part of the dimension table after joining both tables. But this column shall not have missing dates. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors