Forum Discussion
Dates improperly aggregating in visualization
- 9 years ago
A few things you need to fix.
1. My example of using a number (1-12) was an example if you have a Month column. Since you are using Month and Year, you need to make a unique order column for this value. I would make a calc column (query editor) that takes Year*100+Month. This will give you values like 201601 for Jan2016, 201602 for Feb2016 etc. Make sure the data type is numeric and this will allow you to sort correctly across multiple years.
2. You don't need to concantenate this unique sort order column with the Month Year column. Just select the field from the fields list, go to the Modeling tab, and choose Sort By > Unique Sort Order column.
Hi Viper1o34,
You don't need to create other tables, just right click your table in Report view, then select "New Column" to create calculated olumns using the following formulas.
MonthNumber = MONTH('Tablename'[Report Date])
Year = YEAR('TableName'[Report Date])
Month = SWITCH([MonthNumber],
1,"Jan",
2,"Feb",
3,"Mar",
4,"Apr",
5,"May",
6,"Jun",
7,"Jul",
8,"Aug",
9,"Sep",
10,"Oct",
11,"Nov",
12,"Dec",
"Invalid Month Number"
)
MonthYear = CONCATENATE('TableName'[Month],CONCATENATE(",",'TableName'[Year]))
Then put MonthYear into Axis of your visual.
Or you can use Vvelarde's method to create your visual.
Thanks,
Lydia Zhang
Lydia,
Thank you for the help. I have entered the formulas as you described them and I am still not yet to the result I need. The visualization is not properly separating the years by color. It is also not creating a new column for the new year. Rather than a stacked bar graph my goal was to have each separate month as its own bar.
For some reason it is improperly counting. December ONLY has 2016 tickets. Since we have not yet made it to December 2017 its strange it is separating this out. I do not know why it is wanting to separate December and November as these are not the correct months for the distinct color.
How do I create a chart that reads Jan 2016, Feb 2016, Mar 2016 ... Jan 2017 without stacking the colors? Also this new chart is missing data.
Specifically using the formula you provided I have September and June in the data but missing in the visiualization. Its simply ommiting these months entirely. I will provide examples from the report view below.
Current visualization:
Missing Data (June only has one entry but still it should be in the bar graph):
Lastly these bars are not in monthly order. Rather, it is defaulting to Alphabetical order. This is confusing for a viewer and I must have these in the order of the month rather than Alphabetical.
Thank you for the help so far and hopefully I can get this corrected.
Brian
- dkay84_PowerBI9 years agoMicrosoft Employee
You need to put [MonthYear] as the axis. If you have months with no data, they will not be shown by default, but by clicking on the drop down arrow on the field (in the Visuals pane) you can turn on showing values with no data. To sort string values (text) in a non alphabetical way, you need to make a column that has the sort order. So, if you make a table that has month name Jan...Dec, you would need a column that has 1...12 for the months. Then, if you select the month name field and go to the Modeling tab, you can choose "Sort By" and choose the order column.
- Viper1o349 years agoRegular Visitor
Ok I did as you suggested and created a separate column with numbers aligning to the months. However this has created a new issue. I have data going from June (number 6) to December (number 12) and finally January (number 1). If I sort acending or decending I end up with my columns ordered from 12 - 1 or 1-12 wich is incorrect since this data spans 2 years. I need the months to order 6-12 then 1 for January 2017.
Below I have a picture of a decending sort. As you can see it starts at 12 (Dec 2016) and goes backwards to 6 (June 2016) with the last column 1 (January 2017). I think if the data were for only one year your method would work. However still having trouble due to this spanning multiple years. Is there a way to fix this?
- dkay84_PowerBI9 years agoMicrosoft Employee
A few things you need to fix.
1. My example of using a number (1-12) was an example if you have a Month column. Since you are using Month and Year, you need to make a unique order column for this value. I would make a calc column (query editor) that takes Year*100+Month. This will give you values like 201601 for Jan2016, 201602 for Feb2016 etc. Make sure the data type is numeric and this will allow you to sort correctly across multiple years.
2. You don't need to concantenate this unique sort order column with the Month Year column. Just select the field from the fields list, go to the Modeling tab, and choose Sort By > Unique Sort Order column.