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
Beth_H
Frequent Visitor

Dynamic Month X axis with Y axis showing count of values that are fall into that month

Hi there.

 

I have some data that looks similar to the example below. I have a selection of Placement Ids and if they are active in a particular month, then they are flagged with a 1.

 

I want to create a bar chart that shows the name of month (3 months ago, 2 months ago and then last month) on the x axis, and then the total count of Placements on the y axis (i.e. placements flagged in more than one month will be counted multiple times on the same bar chart).

 

 

Placement ID3 Months Ago2 Months AgoLast Month
111 
211 
311 
4 11
5 11
6111
71 1
81 1
91 1
10 11
11  1
12 11
1311 
1411 
15 11
16 11
17 11
18 11
19111
2011

1

 

So far I have managed to create this:

Beth_H_0-1721833081838.png

 

By creating a dynamic Month Table for the x axis shown below:

Beth_H_1-1721833136575.png

 

And a measure for the y axis written as follows:

     PopulationByMonth = SWITCH(MAX('Month Table'[Month]),
     FORMAT(DATE(YEAR(EDATE(TODAY(), -3)), MONTH(EDATE(TODAY(), -3)), 1), "MMMM"), COUNT(Table[Month1]),
     FORMAT(DATE(YEAR(EDATE(TODAY(), -2)), MONTH(EDATE(TODAY(), -2)), 1), "MMMM"), COUNT(Table[Month2]),
     FORMAT(DATE(YEAR(EDATE(TODAY(), -1)), MONTH(EDATE(TODAY(), -1)), 1), "MMMM"), COUNT(Table[Month3])
     )


The numbers are correct! But for the life of me I cannot sort the x axis so that it shows the Months in order. Even though I have added an Index to the Month Table and set that table to Sort by Column > Index, I cannot change it.

 

Is there a way to fix this?

 

Or is there another way to achieve the bar chart that I want?

1 ACCEPTED SOLUTION

Hi Fen Ling, 

 

Thank you for your response, however in my post I described how I had already done these steps. My Month table had an index which was sorted by Index but this made no difference to the order.

 

But I found a fix myself!

In the end I added the Index to the visual itself as a tooltip. This added the Index as an option in the 'Sort axis' option (shown below) and I now have my axis ordered according to the index.

Beth_H_0-1721898284398.png

 

Thanks.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi,@Beth_H 

I am glad to help you.   

 

According to your description, you want to sort the x-axis so that it displays the months in order? 

  

If I understand you correctly, then you can refer to my solution.  

 

First, open the Power Query Editor and find Column From Examples. The exact location is as follows: 

vfenlingmsft_0-1721876439080.png

 

 

Then you can set the order in which you want to display them: 

vfenlingmsft_1-1721876439085.png

Then click the column you want to sort and modify the sorting conditions: 

vfenlingmsft_2-1721876464192.png

 

 

This is the final result: 

vfenlingmsft_3-1721876464193.png

 

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Fen Ling, 

 

Thank you for your response, however in my post I described how I had already done these steps. My Month table had an index which was sorted by Index but this made no difference to the order.

 

But I found a fix myself!

In the end I added the Index to the visual itself as a tooltip. This added the Index as an option in the 'Sort axis' option (shown below) and I now have my axis ordered according to the index.

Beth_H_0-1721898284398.png

 

Thanks.

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.