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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
ngomes
Helper II
Helper II

Data segmentation

Good morning everyone,

I need to compare the last month with the previous one but I would like to use a data segmentation with the months and I would like to know what the last month is, getting the dynamic dax formula

 

thanks for any help you can give me

1 ACCEPTED SOLUTION

Thank you for your help

I ended up solving it with the formula:


FILTER ( ALL ( Sales[Year] ), Year_1 = Sales[Year] )

 

 

in the end it looked like:

 

VAR MonthYear =
Sales[YearselectedMonth2]
VAR Year_1 =
Sales[Selected Year 2-1]
RETURN

CALCULATE (
Sum(Sales[Margin]) ,
FILTER ( ALL ( Sales[Year] ), Year_1 = Sales[Year] )
)

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@ngomes , Not very clear. A various methods to get this month vs last month

 

MTD = CALCULATE(AverageX(values('Date'[Date]), calculate(SUM(Table[Qunatity Produced])) ),DATESMTD('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]))
next month Sales = CALCULATE(SUM(Sales[Sales Amount]),nextmonth('Date'[Date]))
this month = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH('Date'[Date])))
last MTD (complete) Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,MONTH))))
previous month value = CALCULATE(sum('Table'[total hours value]),previousmonth('Date'[Date]))

 

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

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

sorry I didn't explain myself well

I have a scroller where I have the values of the month and the deviation from the previous month

the formulas I currently have are
MarginMonth = if (MONTH(TODAY())= Sales[Month], Sales[Margin],0)
and
MarginMonth-1 = if (MONTH(TODAY())-1= Sales[Month], Sales[Margin],0)

which causes the formulas to be stuck to the current and previous month

what I wanted was for the formulas to be dynamic according to the selection made in the data segmentation made by the user

I hope I was a little clearer now

Hi, @ngomes 

If I understand correctly, you can try to add a seperated calendar table, then try formula as below:

 

MarginMonth =
VAR _today =
    SELECTEDVALUE ( 'calendar1'[Date] )
RETURN
    IF ( MONTH ( _today ) = Sales[Month], Sales[Margin], 0 )
MarginMonth =
VAR _today =
    SELECTEDVALUE ( 'calendar1'[Date] )
RETURN
    IF ( MONTH ( _today )-1 = Sales[Month], Sales[Margin], 0 )

 

Best Regards,
Community Support Team _ Eason

Thank you for your help

I ended up solving it with the formula:


FILTER ( ALL ( Sales[Year] ), Year_1 = Sales[Year] )

 

 

in the end it looked like:

 

VAR MonthYear =
Sales[YearselectedMonth2]
VAR Year_1 =
Sales[Selected Year 2-1]
RETURN

CALCULATE (
Sum(Sales[Margin]) ,
FILTER ( ALL ( Sales[Year] ), Year_1 = Sales[Year] )
)

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors