Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Following the example of the implementation on the github repo:
https://github.com/barakb32/PBI-MTA
And the topics:
https://community.powerbi.com/t5/Desktop/Create-Milestone-Trend-Analysis-MTA-in-Power-BI/m-p/191509
https://community.powerbi.com/t5/Developer/Milestone-Trend-Analysis/m-p/1366360
I want to create a milestone trend analysis like the image below:
My dataset is in the following format:
And my python script:
# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:
# dataset = pandas.DataFrame(M Actual Value, M, M Plan Value)
# dataset = dataset.drop_duplicates()
# Paste or type your script code here:
import matplotlib.pyplot as plt, datetime
import matplotlib.dates as mdates
dataset['Span Date']=pandas.to_datetime(dataset['Span Date'])
dataset['M Actual Value']=pandas.to_datetime(dataset['M Actual Value'])
pivot=pandas.pivot_table(dataset, aggfunc='first', index="M Actual Value", values='Span Date', columns='M')
for column in pivot:
clean=pivot[['45 Line',column]]
clean=clean[clean[column].notnull()]
plt.plot_date(clean['45 Line'],clean[column],xdate=True,ydate=True,ls='-', lw=1)
plt.xticks(rotation=0)
dtFmt = mdates.DateFormatter('%Y-%m') # define the formatting
plt.gca().xaxis.set_major_formatter(dtFmt)
plt.gca().yaxis.set_major_formatter(dtFmt)
plt.show()
The final Output is:
Is there any way to display correct days? I notice years (1600+ etc) that are not in my data.
Solved! Go to Solution.
Hi @kala2
It seems that the problem is in your python statement, under the for column in pivot.
Because some rows with NaT, so you should try to remove the null rows.
I'm not particularly skilled in python either. Maybe this code replace it.
plt.plot_date(clean['45 Line'].dropna(axis=0).index,clean[column].dropna(axis=0).values,xdate=True,ydate=True,ls='-', lw=1)
Best Regards
Community Support Team _ chenwu zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @kala2
It seems that the problem is in your python statement, under the for column in pivot.
Because some rows with NaT, so you should try to remove the null rows.
I'm not particularly skilled in python either. Maybe this code replace it.
plt.plot_date(clean['45 Line'].dropna(axis=0).index,clean[column].dropna(axis=0).values,xdate=True,ydate=True,ls='-', lw=1)
Best Regards
Community Support Team _ chenwu zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 45 | |
| 43 | |
| 38 | |
| 19 | |
| 15 |
| User | Count |
|---|---|
| 67 | |
| 66 | |
| 31 | |
| 28 | |
| 24 |