Forum Discussion
Date Grouping
- 1 year ago
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.
- Anonymous1 year ago
Hi Anonymous ,
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.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.
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.
Hi Anonymous ,
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.
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.
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.