Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
DanielaAttard
New Member

Date Grouping

Hi,

 

I have a line chart showing data during a period compared to the same period of previous year. Example below.

When using the bins to group the data monthly instead of daily it doesn't work and shows just the current year data.


Can someone please advise how to group the data into monthly instead of daily that would show both the line for current year and the line for previous year on same visual ?

 

DanielaAttard_0-1733222641892.png

 

 

2 ACCEPTED SOLUTIONS

Use the calculated table in my reply. Mark the calendar as a dates table. Sort Month name by month number. Disable time auto date/time. Add both year and month columns from the calendar table (not from the auto-generated hierarchy) to the viz. Expand the hierarchy in the viz. Apply your PY calculation to the DateTable columns and not to the one from your fact table.

danextian_0-1733224594668.png

danextian_1-1733224666231.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

Anonymous
Not applicable

Hi @DanielaAttard ,


Please refers to the following steps.
Create a calendar table.

Calendar = 
ADDCOLUMNS(
    CALENDAR(MIN('Table'[Date]),MAX('Table'[Date])),
    "Year",YEAR([Date]),
    "Month",MONTH([Date]),
    "Year-Month",FORMAT([Date],"yyyy-mm")
)


The model is as follows.

vdengllimsft_0-1733730977029.png

 

 The Total PY measure is shown below.

TotalPY = 
CALCULATE(SUM('Table'[Amount]),
DATEADD('Calendar'[Date],-1,YEAR)
)


Use the Year-Month column of the calendar table as the X-axis, Total CY as the Y-axis, and Total PY as the secondary Y-axis to build the line chart.
The final result is as follows.

vdengllimsft_1-1733731139875.png


Please see the attached pbix for reference.

Best Regards,
Dengliang Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @DanielaAttard ,


Please refers to the following steps.
Create a calendar table.

Calendar = 
ADDCOLUMNS(
    CALENDAR(MIN('Table'[Date]),MAX('Table'[Date])),
    "Year",YEAR([Date]),
    "Month",MONTH([Date]),
    "Year-Month",FORMAT([Date],"yyyy-mm")
)


The model is as follows.

vdengllimsft_0-1733730977029.png

 

 The Total PY measure is shown below.

TotalPY = 
CALCULATE(SUM('Table'[Amount]),
DATEADD('Calendar'[Date],-1,YEAR)
)


Use the Year-Month column of the calendar table as the X-axis, Total CY as the Y-axis, and Total PY as the secondary Y-axis to build the line chart.
The final result is as follows.

vdengllimsft_1-1733731139875.png


Please see the attached pbix for reference.

Best Regards,
Dengliang Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

dharmendars007
Super User
Super User

Hello @DanielaAttard , 

 

Instead of adding Dates you can choose month & Year Column if it is avaible or you can create one.

 

If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes 👍 are much appreciated!

 

Thank You

Dharmendar S

LinkedIN 

I tried that as per below. What am I missing please?

 

DanielaAttard_0-1733223954653.png

 

Use the calculated table in my reply. Mark the calendar as a dates table. Sort Month name by month number. Disable time auto date/time. Add both year and month columns from the calendar table (not from the auto-generated hierarchy) to the viz. Expand the hierarchy in the viz. Apply your PY calculation to the DateTable columns and not to the one from your fact table.

danextian_0-1733224594668.png

danextian_1-1733224666231.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
danextian
Super User
Super User

Hi @DanielaAttard 

 

Use a separate dates table that contains columns for several date elements - year, quarter, month number, month name, month and year etc. Mark that as a dates table and create a a one-to-many single direction relationshiop  from the date column from the dates table and the one from the fact table.  Below is a basic DAX calculated table formula

 

ADDCOLUMNS (
    CALENDAR ( DATE ( 2024, 1, 1 ), DATE ( 2024, 12, 31 ) ),
    "Year", YEAR ( [Date] ),
    "Month Number", MONTH ( [Date] ),
    "Month Name", FORMAT ( [Date], "mmmm" )
)

 

 Attached is a sample pbix with date tables created in either M or DAX.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

I already tried that as per below. What am I missing please?

 

DanielaAttard_0-1733223788725.png

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.