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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.