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

Join 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.

Reply
NicoBoss
New Member

Overlaying graphs with independant tables using python or ...

Good day, 

I have 2 independant graphs associated to 2 independant table.

table1 with x1-values y1-values and table2 with x2-values y2-values 

All data are decimals, BUT x1-values do not match x2-values

Is is possible to have the two curve on the same graph ? 

I guess it should be easy but i am struggling

Thank you so much.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @NicoBoss 

 

Thank you very much govind_021 for your prompt reply.

 

If Time1 is not equal to Time2, I suggest you create a bridge table as follows:

 

“Time1”

vnuocmsft_0-1736992060474.png

 

"Time2"

vnuocmsft_1-1736992078262.png

 

Create a new table.

 

Bridge Table = 
UNION(
    SELECTCOLUMNS(
        'Table1',
        "Time",
        'Table1'[Time1]),
        SELECTCOLUMNS(
        'Table2',
        "Time",
        'Table2'[Time2])
)

 

vnuocmsft_2-1736992137815.png

 

Table1 and Table2 create relationships with the bridge table respectively.

 

vnuocmsft_3-1736992210031.png

 

Create a Python visual.

 

import matplotlib.pyplot as plt

# Create figure and axis
ax = plt.gca()

dataset.plot(kind= "line", x='Time1', y='Depth1', color= "Red", ax= ax)

dataset.plot(kind= "line", x='Time2', y='Depth2', color= "Blue", ax= ax)

# Show plot
plt.show()

 

Here is the result.

 

vnuocmsft_4-1736992414505.png

 

Regards,

Nono Chen

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

3 REPLIES 3
govind_021
Responsive Resident
Responsive Resident

Hi @NicoBoss 
Can you give more context to your question by adding images of the problem , if confidential then with dummy data.

Thanks Sure,  I tried the code below. 

This code is working fine if Time1=Time2, then i can create a table with 3 column only, X=Time1 Y1=Depth1 and Y2=Depth2 and plot 2 curves.

But Time1≠Time2, also the table1 is not the same size as table2, so I cannot merge and I get the error : "can't display the data because PowerBI can't determine the relationship between two or more fields"

Indeed they are 2 different tables from 2 different queries. 

Time1/Depth1 and Time2/Depth2 are from 2 different datatables in the same powerbi, I opened a Py-Python Visual, draged and droped those tables in the "Values" field. 

Basically just want to overlay 2 curves (without the same dimension), should be easy? I am struggling for more than 1 day... I read it is not so easy in PowerBI DAX but they are ways around, but so far still searching... 

---

import matplotlib.pyplot as plt
import numpy as np
f, a = plt.subplots()
data = dataset
x1 = data['Time1']
y1 = data['Depth1']
x2 = data['Time2']
y2 = data['Depth2']
a.plot(x1,y1,'r--')
a.plot(x2,y2,'--')
plt.show()
---
Anonymous
Not applicable

Hi @NicoBoss 

 

Thank you very much govind_021 for your prompt reply.

 

If Time1 is not equal to Time2, I suggest you create a bridge table as follows:

 

“Time1”

vnuocmsft_0-1736992060474.png

 

"Time2"

vnuocmsft_1-1736992078262.png

 

Create a new table.

 

Bridge Table = 
UNION(
    SELECTCOLUMNS(
        'Table1',
        "Time",
        'Table1'[Time1]),
        SELECTCOLUMNS(
        'Table2',
        "Time",
        'Table2'[Time2])
)

 

vnuocmsft_2-1736992137815.png

 

Table1 and Table2 create relationships with the bridge table respectively.

 

vnuocmsft_3-1736992210031.png

 

Create a Python visual.

 

import matplotlib.pyplot as plt

# Create figure and axis
ax = plt.gca()

dataset.plot(kind= "line", x='Time1', y='Depth1', color= "Red", ax= ax)

dataset.plot(kind= "line", x='Time2', y='Depth2', color= "Blue", ax= ax)

# Show plot
plt.show()

 

Here is the result.

 

vnuocmsft_4-1736992414505.png

 

Regards,

Nono Chen

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

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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