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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

Bring data from the last selected period

Hello All,

 

Im trying to compare 2 different periods, being the las period a random period and not exactly the last month. Im working with a Matrix but in the rows its bringing the total instead of split by the category:

 

The matrix is repeating in all the rows the same number of the total

julianacoelho22_0-1670594982699.png

But this should be the correct split

julianacoelho22_1-1670595045392.png

This is the formula, but I have no idea how to correct it to bring me the right data:

Test =
VAR CurrentYearMonth = SELECTEDVALUE ( Query1[Date])
VAR PreviousYearMonth =
    CALCULATE(
        MAX(Query1[Date]),
        ALLSELECTED(Query1),
        KEEPFILTERS(Query1[Date] < CurrentYearMonth)
    )
VAR Result =
    CALCULATE(
        DISTINCTCOUNT(Query1[ModelColor 2]),
        ALLSELECTED(Query1),
        Query1[Date] = PreviousYearMonth
       )
RETURN
    Result

 

 

Thakn you in advance.

Juliana

1 REPLY 1
amitchandak
Super User
Super User

@Anonymous , Last month based on today

 

LMTD Today=
var _min = eomonth(today(),-2)+1
var _max1 = today()
var _max = date(year(_max1),month(_max1)-1, day(_max1))
return
CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

 

 

Last Month Today =
var _min = eomonth(today(),-2)+1
var _max = eomonth(today(),-1)
return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

 

or use all in both meausre like this

 

Last Month Today =
var _min = eomonth(today(),-2)+1
var _max = eomonth(today(),-1)
return CALCULATE([Net], FILTER(all('Date'),'Date'[Date] >=_min && 'Date'[Date] <= _max))

 

if you select any month and want that month and last month then TI can help

examples

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))
MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))

 

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

 

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

 

 

In case you need two slicers

 

How to use two Date/Period slicers

https://youtu.be/WSeZr_-MiTg

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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