Forum Discussion
Combining Two Stacked Bar Charts into One
Hi Experts,
I have two stacked Bar Charts.
- Selected MonthYear Sales.
- Last Year Same Period Sales.
I would like to combine these two Stacked bar Charts.
Here are the details of the existing charts:
- Selected MonthYear Sales
X-Axis: MonthYear
Y-Axis: Sales (calculated as SUM(Orders[Sales]))
Legend: Day
2. Last Year Same Period Sales
X-Axis: LastYearMonth
Y-Axis: LastYearSales (calculated with the following DAX formula):
CALCULATE(
SUM(Orders[Sales]),
FILTER(
ALL('Master Calendar'),
'Master Calendar'[Date] = MAX('Master Calendar'[LastYearDate])
))
Legend: Day
My goal is to merge these into a single chart, where each bar represents the sales data: one for the "Selected MonthYear" and another for the "LastYearMonth".
Attached is the PBIX:
SelectedMonthYear&LastYearSamePeriod.pbix
Anyone, Please help.
Thank you!
Hi puru85 ,
I think that you need to redo your Last Year sales I have redone it to:
LastYearSales_ New Version= CALCULATE( SUM(Orders[Sales]), DATEADD('Master Calender'[Date], -1 , YEAR))Created a field parameter using the Sales and Last Year Sales New version and added the following measure:
Measure Selection = SWITCH(SELECTEDVALUE(Parameter[Parameter Order]), 0, [Sales],1,[LastYearSales_ New Version])Create the visualization in the following way:
- X-axis:
- MonthYear
- Parameter
- Y-Axis
- Measure Selection
- Legend
- Day
See file attach.
- X-axis:
Hi puru85 ,
After your question just got an easier solution:
- Create a table with the MonthYear column (disconnected table)
- Add the following measure:
Measure Selection = SWITCH( TRUE(), SELECTEDVALUE('Month Table'[MonthYear]) in VALUES('Master Calender'[MonthYear]), [Sales], SELECTEDVALUE('Month Table'[MonthYear]) in VALUES('Master Calender'[LastYearMonth]),[LastYearSales])- Create your visualization using the following setup:
- X-Axis
- MonthYear (from the new table)
- Y-Axis
- Measure Selection
- Legend
- Day
- X-Axis
If you select more than one month this will present the information for current year and previous years selection.
See attach file.
4 Replies
- MFelix
Super User
Hi puru85 ,
I think that you need to redo your Last Year sales I have redone it to:
LastYearSales_ New Version= CALCULATE( SUM(Orders[Sales]), DATEADD('Master Calender'[Date], -1 , YEAR))Created a field parameter using the Sales and Last Year Sales New version and added the following measure:
Measure Selection = SWITCH(SELECTEDVALUE(Parameter[Parameter Order]), 0, [Sales],1,[LastYearSales_ New Version])Create the visualization in the following way:
- X-axis:
- MonthYear
- Parameter
- Y-Axis
- Measure Selection
- Legend
- Day
See file attach.
- X-axis:
- MFelix
Super User
Hi puru85 ,
After your question just got an easier solution:
- Create a table with the MonthYear column (disconnected table)
- Add the following measure:
Measure Selection = SWITCH( TRUE(), SELECTEDVALUE('Month Table'[MonthYear]) in VALUES('Master Calender'[MonthYear]), [Sales], SELECTEDVALUE('Month Table'[MonthYear]) in VALUES('Master Calender'[LastYearMonth]),[LastYearSales])- Create your visualization using the following setup:
- X-Axis
- MonthYear (from the new table)
- Y-Axis
- Measure Selection
- Legend
- Day
- X-Axis
If you select more than one month this will present the information for current year and previous years selection.
See attach file.