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
Anonymous
Not applicable

Show previous month rows based on slicer

I want to make a table that lets me see all the rows corresponding to a previous month based on a slicer. For example, if I click the slicer on September, I want the table to show every row corresponding to August.

5 REPLIES 5
amitchandak
Super User
Super User

@Anonymous , Do you have Date. If Yes, then you can use time intelligence. If not create separate a month year table with Rank and use that. Refer to my blog

Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKA

 

Example of measures

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))

last year MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-12,MONTH)))
last year MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-12,MONTH))))
Month behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Month))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
Next month value =  CALCULATE(sum(''Table''[total hours value]),nextmonth('Date'[Date]))
Next to next  month value =  CALCULATE(sum(''Table''[total hours value]),nextmonth(dateadd('Date'[Date],1,MONTH)))
previous to previous month value =  CALCULATE(sum(''Table''[total hours value]),previousmonth(dateadd('Date'[Date],-1,MONTH)))

Will this work if a January date is selected? For example, January 2022 is selected will is return Decembers 2021 data for the Month behind Sales measure?

You need a calendar table. https://exceleratorbi.com.au/power-pivot-calendar-tables/
join it to your data table using the date column. Use the month/year columns from your calendar in the slicer.  As you would know, when you click a slicer for Sept, the rows for Sept will show in the visual. This is how it works: the filter on calendar will directly filter your data. You need to manipulate the filter with a measure, so you need a measure that returns a value for the previous month in the visual. The measure will depend on your data, but could look like this

Last Month Data = CALCULATE(countrows(datatable),PREVIOUSMONTH(Calendar[date]))



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
Anonymous
Not applicable

I created the Measure, along with te calendar table. I still don´t understand where or how should I use the measure so the filter context based on month changes to the previous of the selected in the slicer. I´m sorry, Im just starting to learn Dax.

You said you want a table to show rows. Add a table visual to the report, add the columns you want to see from the source data table into the table visual. Add the measure into the visual too. Only the rows from the source data from the prior month will show in the table visual. If there is no unique key/ID in the source data table, duplicate rows will be combined, and the measure for that row will be >1



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

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.

Top Solution Authors