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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Puja
Helper III
Helper III

Previous Month Flag

Hi ,

I need some help with Previous month flag. When user selecta a date Ex: 3/1/2020, the result should be pevious month (2/1/2020) 

Dates Test data.

1/1/2020
2/1/2020
3/1/2020
4/1/2020
5/1/2020
6/1/2020
7/1/2020
8/1/2020
9/1/2020
10/1/2020
11/1/2020
12/1/2020
1/1/2021
2/1/2021
3/1/2021
4/1/2021
5/1/2021

 

 

2 ACCEPTED SOLUTIONS
FreemanZ
Super User
Super User

Hi @Puja 

1) create a table like:

Table2 = Table1

2) plot a table visual with Table1[Date] column and a measure like:

Measure = 
IF(
    SELECTEDVALUE(Table1[Date]) = EDATE(SELECTEDVALUE(Table2[Date]),-1),
    1,0
)

it worked like:

FreemanZ_2-1682086187294.png

 

FreemanZ_1-1682086140254.png

 

View solution in original post

Jihwan_Kim
Super User
Super User

Hi, 

I am not sure how your datamodel looks like, but please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1682086463340.png

 

 

Expected result measure: =
VAR _selectedmonthyear =
    MAX ( Data[Date_test] )
VAR _selectedday =
    DAY ( _selectedmonthyear )
VAR _prevendofmonthdate =
    EOMONTH ( _selectedmonthyear, -1 )
RETURN
    DATE ( YEAR ( _prevendofmonthdate ), MONTH ( _prevendofmonthdate ), _selectedday )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi, 

I am not sure how your datamodel looks like, but please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1682086463340.png

 

 

Expected result measure: =
VAR _selectedmonthyear =
    MAX ( Data[Date_test] )
VAR _selectedday =
    DAY ( _selectedmonthyear )
VAR _prevendofmonthdate =
    EOMONTH ( _selectedmonthyear, -1 )
RETURN
    DATE ( YEAR ( _prevendofmonthdate ), MONTH ( _prevendofmonthdate ), _selectedday )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hi @Jihwan_Kim , Thanks a lot for your solution. It is working as expected.

How can I referance your flag in the below measure.

The ask from the user is when he selects a date , it should show previous month actuals. With TREATAS, i am not able to get the correct results.(I have to use TREATAS because there is no relation b/w Date and actuals tables in AAS model)

Actual = CALCULATE([Actual], TREATAS(SUMMARIZE(Forecast,Forecast[Year SF],Forecast[Month SF]),
DimDate[Year],DimDate[Month]))

 

Thank u

 

 

FreemanZ
Super User
Super User

Hi @Puja 

1) create a table like:

Table2 = Table1

2) plot a table visual with Table1[Date] column and a measure like:

Measure = 
IF(
    SELECTEDVALUE(Table1[Date]) = EDATE(SELECTEDVALUE(Table2[Date]),-1),
    1,0
)

it worked like:

FreemanZ_2-1682086187294.png

 

FreemanZ_1-1682086140254.png

 

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.