Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers!
Enter the sweepstakes now!Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.
Hi everybody, I'm having some issues using the stacked bar chart in Power BI. For the moment I'm using 4 measures on the Y axis, this measures are based on the table "Data". My example is below:
Tabla named "Data":
Net Base Demand | Net Int Demand | Net Peak Demand | Load Base Demand | Load Int Demand | Load Peak Demand |
1450 | 1200 | 500 | 1250 | 1150 | 1100 |
Load =
SWITCH(TRUE(),
SELECTEDVALUE(Horario[Horario]) = "Base", 'Data'[Load Base Demand],
SELECTEDVALUE(Horario[Horario]) = "Intermedio", IF ('Data'[Net Int Demand]>'Data'[Load Int Demand], 'Data'[Load Int Demand],'Data'[Net Int Demand])
Net =
SWITCH(TRUE(),
SELECTEDVALUE(Horario[Horario]) = "Base", -('Data'[Load Base Demand]-'Data'[Net Base Demand]),
SELECTEDVALUE(Horario[Horario]) = "Intermedio", ABS('Data'[Load Int Demand]-'Data'[Net Int Demand])
Net Chart BESS Peak =
SWITCH(TRUE(),
SELECTEDVALUE(Horario[Horario]) = "Punta", 'Data'[Net Peak Demand])
Load Chart BESS Peak =
SWITCH(TRUE(),
SELECTEDVALUE(Horario[Horario]) = "Punta", [Peak Demand Dif])
On the X axis, I'm using a column from a table like the following:
Horario |
Base |
Intermedio |
Punta |
Using this on the stacked bar chart I got the following result:
This is the result I want, I just need to hide the legends called as "Gráfica Net perfil BESS Punta" and the one "Gráfica Load perfil BESS Punta". I also need let the chart continue to show the legends named as "Load" and "Net"
Does anyone know how to do it?
Solved! Go to Solution.
Hi everybody, I found a solution to my problem. The solution is use the matplotlib library from python. The code I used was the following:
# El código siguiente, que crea un dataframe y quita las filas duplicadas, siempre se ejecuta y actúa como un preámbulo del script:
# dataset = pandas.DataFrame(undefined, undefined.1, undefined.2, undefined.3)
# dataset = dataset.drop_duplicates()
# Pegue o escriba aquí el código de script:
import matplotlib as mb
import matplotlib.pyplot as plt
import numpy as np
#Hacer bonito el gráfico
mb.rcParams['font.size'] =12
mb.rcParams['text.color'] ="#000000"
mb.rcParams['axes.labelcolor']="white"
mb.rcParams['xtick.color']="white"
mb.rcParams['ytick.color']="white"
#Definir Parámetros
Horario = dataset.loc[0:6,'Horario'].tolist()
Load_base= dataset.loc[0:6,'Grafica Load perfil BESS Base'].tolist()
Net_base = dataset.loc[0:6,'Grafica Net perfil BESS Base'].tolist()
Load_int= dataset.loc[0:6,'Grafica Load perfil BESS Int'].tolist()
Net_int = dataset.loc[0:6,'Grafica Net perfil BESS Int'].tolist()
Load_peak = dataset.loc[0:6,'Gráfica Load perfil BESS punta'].tolist()
Net_peak = dataset.loc[0:6,'Gráfica Net perfil BESS punta'].tolist()
#Formato Condicional para demanda Intermedio
Int_demand_conditional = dataset.loc[0:6,'Intermediate Demand Dif tarjeta']
color_cond_Int_1 = np.where(Int_demand_conditional>0,"#B3B3B3","#FBED1D")
color_cond_Int_2 = np.where(Int_demand_conditional>0, "#FBED1D", "#000000")
color_cond_Int_edgecolor_1 = np.where(Int_demand_conditional>0,"#B3B3B3","#FBED1D")
color_cond_Int_edgecolor_2 = np.where(Int_demand_conditional>0, "#FBED1D", "#B3B3B3")
#Cambiar color de la parte de afuera del fondo
plt.figure(facecolor="#000000")
#Cambiar color de fondo
ax=plt.axes()
ax.set_facecolor("#000000")
#Crear barras
plt.bar (Horario, Load_base, color ="#b3b3b3", edgecolor="#b3b3b3",linewidth=2 )
plt.bar (Horario, Net_base, bottom = Load_base, color = "#FBED1D", edgecolor="#FBED1D",linewidth=2)
plt.bar (Horario, Load_int, color = color_cond_Int_1, edgecolor=color_cond_Int_edgecolor_1,linewidth=2 )
plt.bar (Horario, Net_int, bottom = Load_int, color = color_cond_Int_2, edgecolor=color_cond_Int_edgecolor_2,linewidth=2 )
plt.bar (Horario,Net_peak, color ="#FBED1D", edgecolor="#FBED1D",linewidth=2 )
plt.bar (Horario,Load_peak, bottom = Net_peak, color ="#000000", edgecolor="#b3b3b3",linewidth=2 )
#Nombrar ejes
plt.xlabel("Horario")
plt.ylabel("Demanda [kW]")
#Poner leyendas
plt.legend(["Load", "Net"])
plt.show()
Hi everybody, I found a solution to my problem. The solution is use the matplotlib library from python. The code I used was the following:
# El código siguiente, que crea un dataframe y quita las filas duplicadas, siempre se ejecuta y actúa como un preámbulo del script:
# dataset = pandas.DataFrame(undefined, undefined.1, undefined.2, undefined.3)
# dataset = dataset.drop_duplicates()
# Pegue o escriba aquí el código de script:
import matplotlib as mb
import matplotlib.pyplot as plt
import numpy as np
#Hacer bonito el gráfico
mb.rcParams['font.size'] =12
mb.rcParams['text.color'] ="#000000"
mb.rcParams['axes.labelcolor']="white"
mb.rcParams['xtick.color']="white"
mb.rcParams['ytick.color']="white"
#Definir Parámetros
Horario = dataset.loc[0:6,'Horario'].tolist()
Load_base= dataset.loc[0:6,'Grafica Load perfil BESS Base'].tolist()
Net_base = dataset.loc[0:6,'Grafica Net perfil BESS Base'].tolist()
Load_int= dataset.loc[0:6,'Grafica Load perfil BESS Int'].tolist()
Net_int = dataset.loc[0:6,'Grafica Net perfil BESS Int'].tolist()
Load_peak = dataset.loc[0:6,'Gráfica Load perfil BESS punta'].tolist()
Net_peak = dataset.loc[0:6,'Gráfica Net perfil BESS punta'].tolist()
#Formato Condicional para demanda Intermedio
Int_demand_conditional = dataset.loc[0:6,'Intermediate Demand Dif tarjeta']
color_cond_Int_1 = np.where(Int_demand_conditional>0,"#B3B3B3","#FBED1D")
color_cond_Int_2 = np.where(Int_demand_conditional>0, "#FBED1D", "#000000")
color_cond_Int_edgecolor_1 = np.where(Int_demand_conditional>0,"#B3B3B3","#FBED1D")
color_cond_Int_edgecolor_2 = np.where(Int_demand_conditional>0, "#FBED1D", "#B3B3B3")
#Cambiar color de la parte de afuera del fondo
plt.figure(facecolor="#000000")
#Cambiar color de fondo
ax=plt.axes()
ax.set_facecolor("#000000")
#Crear barras
plt.bar (Horario, Load_base, color ="#b3b3b3", edgecolor="#b3b3b3",linewidth=2 )
plt.bar (Horario, Net_base, bottom = Load_base, color = "#FBED1D", edgecolor="#FBED1D",linewidth=2)
plt.bar (Horario, Load_int, color = color_cond_Int_1, edgecolor=color_cond_Int_edgecolor_1,linewidth=2 )
plt.bar (Horario, Net_int, bottom = Load_int, color = color_cond_Int_2, edgecolor=color_cond_Int_edgecolor_2,linewidth=2 )
plt.bar (Horario,Net_peak, color ="#FBED1D", edgecolor="#FBED1D",linewidth=2 )
plt.bar (Horario,Load_peak, bottom = Net_peak, color ="#000000", edgecolor="#b3b3b3",linewidth=2 )
#Nombrar ejes
plt.xlabel("Horario")
plt.ylabel("Demanda [kW]")
#Poner leyendas
plt.legend(["Load", "Net"])
plt.show()
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information or anything not related to the issue or question.
If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...
@lbendlin Thanks for the recommendation, I already updated the post. I made a little bit changes from the original because I found a way of edit sepparate bars.
Check out the May 2025 Power BI update to learn about new features.
Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.
User | Count |
---|---|
72 | |
71 | |
71 | |
50 | |
46 |
User | Count |
---|---|
45 | |
38 | |
29 | |
29 | |
28 |