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
CharlesL
Regular Visitor

How to use Date slicer with column for each month

I have a table that I am trying to filter using a date slicer.  The problem is that the table is set up with a month/year column for each month, and a row for each of over 300 sites, and an event count for each location during any given month. (example below)

 

I have a separate "Date" table that I am using as a Dim table, but I cannot create a relationship with 16 month columns.

 

I have thought of transposing the data into 3 columns, Site, Date, Quantity, then I can have a 1 to many relationship with the date.  The data transposition will mean writing a macro i guess which is possible, but hoping for a better way.  The database is updated monthly by adding a new column for the new month.

 

Any suggestions would be appreciated.

Site #JanFebMarAprilMayJuneJulyAugSepOctNovDevJanFebMarAprilMayTotal 
4382 1325232 12 412 30
5232  21 11212 1121 17
784  1 11 31311  32 17
792 2    1  3  11 1110
800   1 113 1 1 111 11

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Is this table in your Power BI model? If so, you do not need to write a macro. All you need to do is open query editor, select all the month/year columns, then click on "Unpivot Columns" as shown in the screenshot below. This will create a 3 column table as you mentioned and then you can create a relationship between the new date column and your date dim table.

unpivot.png

View solution in original post

5 REPLIES 5
CharlesL
Regular Visitor

Thanks for the suggestion, but it didnt work for me.  When I selected all the date columns, i lost the other two, and then it only unpivoted a single month at a time.

 

I basically need each site number to end up with 24 rows (one per month).  The first column would be site number, the second would have the date, and the third the number of occurances for that site, that month.

Not sure if there is an easy way in PQ to make that happen.

Anonymous
Not applicable

You need to make sure the date columns have proper dates in them and not just the month number because this will merge all months together even if they belong to different years. If your month columns only contain the month, you should replace it with the month starting date. As for the unpivot transformation, you are definitely doing something wrong for it not to work. Can you share the pbix and data source for us to further investigate? 

Let me mess with the dates, and try the transformation again...If I am still stuck, I will convert from MM/YYY to MM/DD/YYYY and see what happens...thx

While I was not able to get the suggestion to work, I was able to get with the team providing the data and have them provide access to the root data, vs the chart they were providing.  Direct source is always better, now I am ok with proceeding to provide the visualizations required.  

 

Thanks for your help.  I am still going to mess with the unpivoting to better understand how it works!

Anonymous
Not applicable

Is this table in your Power BI model? If so, you do not need to write a macro. All you need to do is open query editor, select all the month/year columns, then click on "Unpivot Columns" as shown in the screenshot below. This will create a 3 column table as you mentioned and then you can create a relationship between the new date column and your date dim table.

unpivot.png

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.