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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Metricbits
Frequent Visitor

Dynamic chart X axis - dates

Hello everyone,

 

I have this page with the balance sheet, which is filtered to one particular month (June 2021, in this case on the screenshot).

Also, I have a chart to the right of the balance sheet that I want to be showing the previous 12 months from the selected month (July 2020 to June 2021).

Screenshot_1.jpg

 

The way it currently works is - I disconnected the chart from the period selector that picks a period for the balance sheet and added another slicer that is only connected to the chart to pick the last 12 months manually.

 

I feel like there should be a better way to do this, so that chart can dynamically show the last 12 months from the period slicer that controls the balance sheet. Does anyone know if this is possible?

1 ACCEPTED SOLUTION
HashamNiaz
Solution Sage
Solution Sage

Hi @Metricbits !

You can create a new measure using following DAX;

 

 

Assets Last (N) Month = 
    VAR _CurrentMonth = MAX('Calendar'[Date])
    VAR _LastNMonths = -12
    VAR _DatesPeriod = DATESINPERIOD('Calendar'[Date], _CurrentMonth, _LastNMonths, MONTH)
RETURN
    CALCULATE([Assets], _DatesPeriod)

 

 

This measure will return the Last (N) months (in this case Last 12 months) [Assets] value. Assuming you have Assets measure.

 

You can replace the [Assets] wiht your actual measure, it will bring Last 12 months value for that mesure.

 

You can have still have your Calendar / Date dimension table connected to your Fact table. From Date slicer it will pick up the selected date value & then go back 12 months.

 

To plot this on chart, you need to create a Dummy date column in your Fact table using below DAX;

 

 

Calendar = EOMONTH(FactTable[Date], 0)

 

 

[FactTable] will be the name of your Fact tabl & Date will be its date column. Now you use this field in your chart axis & place [Assets Last (N) Months] measure into values.

 

Regards,

Hasham

View solution in original post

2 REPLIES 2
HashamNiaz
Solution Sage
Solution Sage

Hi @Metricbits !

You can create a new measure using following DAX;

 

 

Assets Last (N) Month = 
    VAR _CurrentMonth = MAX('Calendar'[Date])
    VAR _LastNMonths = -12
    VAR _DatesPeriod = DATESINPERIOD('Calendar'[Date], _CurrentMonth, _LastNMonths, MONTH)
RETURN
    CALCULATE([Assets], _DatesPeriod)

 

 

This measure will return the Last (N) months (in this case Last 12 months) [Assets] value. Assuming you have Assets measure.

 

You can replace the [Assets] wiht your actual measure, it will bring Last 12 months value for that mesure.

 

You can have still have your Calendar / Date dimension table connected to your Fact table. From Date slicer it will pick up the selected date value & then go back 12 months.

 

To plot this on chart, you need to create a Dummy date column in your Fact table using below DAX;

 

 

Calendar = EOMONTH(FactTable[Date], 0)

 

 

[FactTable] will be the name of your Fact tabl & Date will be its date column. Now you use this field in your chart axis & place [Assets Last (N) Months] measure into values.

 

Regards,

Hasham

Worked like magic. Thank you so much!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.