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
PwrBI01
Post Patron
Post Patron

Show data until selected month of the last year

Hi guys,

 

I have a calendar table and a date table and I am trying to create a chart that shows the monthly sales until the selected date of the last year.

 

So, for example:

a) If I select June it should show the following chart:

 

Imagen1.png

b) If I select October, it should show the following chart:

Imagen2.png

 

All of the data should be from the last year of calendar table.

 

Is there a way to get it? 

 

I tried this way: https://community.powerbi.com/t5/Desktop/Show-data-until-selected-month/m-p/705571 but I am having problems with the measure 'Compare to' and I don't know how to do it with just the last year of calendar table.

 

Thanks in advance.

 

Regards.

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @PwrBI01 ,

 

Based on my test , you firstly need to create a new table with MonthName column for slicer using the following formula:

ForSlicer = DISTINCT(SELECTCOLUMNS('Calendar',"MonthNo",[Date].[MonthNo],"MonthName",[Date].[Month]))

Month table for slicer.PNG

 

Then try this:

Measure = 
var _lastYear=MAXX(ALL('Calendar'),YEAR([Date]))
var _month=MAX('ForSlicer'[MonthNo])
return CALCULATE(SUM('Date'[Value]),FILTER('Date',YEAR([Date])=_lastYear && MONTH([Date])<=_month))

The final output is shown below:

sum for selected month of the last year.gif

 

Best Regards,
Eyelyn Qin
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

2 REPLIES 2
v-eqin-msft
Community Support
Community Support

Hi @PwrBI01 ,

 

Based on my test , you firstly need to create a new table with MonthName column for slicer using the following formula:

ForSlicer = DISTINCT(SELECTCOLUMNS('Calendar',"MonthNo",[Date].[MonthNo],"MonthName",[Date].[Month]))

Month table for slicer.PNG

 

Then try this:

Measure = 
var _lastYear=MAXX(ALL('Calendar'),YEAR([Date]))
var _month=MAX('ForSlicer'[MonthNo])
return CALCULATE(SUM('Date'[Value]),FILTER('Date',YEAR([Date])=_lastYear && MONTH([Date])<=_month))

The final output is shown below:

sum for selected month of the last year.gif

 

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

Thank you very much @v-eqin-msft,

 

I wasn't able to do it.

 

Regards.

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.