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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

Pull data in different columns of one table into another table

I have one table (Shiptracking history) with departure, arrival, mass columns. There are entries with the same departure or same arrival date.

Capture22.PNG

 

I would like to create another table with a calendar date, exports & imports on each day. Creating the calendar date is easy as shown below.

 

Calendar = CALENDAR ( MIN(MIN('Shiptracking history'[Arrival]),MIN('Shiptracking history'[Departure])), MAX(MAX('Shiptracking history'[Arrival]),MAX('Shiptracking history'[Departure])) )

Creating the Exports and Imports columns is the problem I have.  First, I attempted to establish a relationship between the Date in the Calendar table and the Departure/Arrival in the Shiptracking history table. That does not seem to be legit and one of the relationships is not active.

 

Capture21.PNG

 

Then I was hoping to bring in the Exports and the Imports using the following code

 

Exports = SUMX(RELATEDTABLE('Shiptracking history'),'Shiptracking history'[Mass]))
Imports = SUMX(RELATEDTABLE('Shiptracking history'),'Shiptracking history'[Mass]))

 But clearly it doesn’t work and I get an error.

 

Capture23.PNG

 

How can I generate Exports and Imports in the Calendar table, using the data in the Shiptracking history table? I also experimented with SELECTCOLUMNS but I couldn't make it work.

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @Anonymous,

 

Please remove the relationship between two tables, and try this:

Exports =
CALCULATE (
    SUM ( 'Shiptracking history'[Mass] ),
    FILTER (
        'Shiptracking history',
        'Shiptracking history'[Departure] = EARLIER ( Calendar[Date] )
    )
)

Imports =
CALCULATE (
    SUM ( 'Shiptracking history'[Mass] ),
    FILTER (
        'Shiptracking history',
        'Shiptracking history'[Arrival] = EARLIER ( Calendar[Date] )
    )
)

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yulgu-msft
Employee
Employee

Hi @Anonymous,

 

Please remove the relationship between two tables, and try this:

Exports =
CALCULATE (
    SUM ( 'Shiptracking history'[Mass] ),
    FILTER (
        'Shiptracking history',
        'Shiptracking history'[Departure] = EARLIER ( Calendar[Date] )
    )
)

Imports =
CALCULATE (
    SUM ( 'Shiptracking history'[Mass] ),
    FILTER (
        'Shiptracking history',
        'Shiptracking history'[Arrival] = EARLIER ( Calendar[Date] )
    )
)

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@v-yulgu-msft

Awesome, thank you so much for your response, this works for me. Much appreciated.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors