Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more
Hello,
I have a table like the below, I would like to add some additional columns that flag (In prev month? & In next month?)-
a) If this record appeared in the prior month?
B) If this record appreared in the next month?
*Please note Month-Year field is a Date type field
Thank you so much for your help 🙂
| Month-Year | ID | In prev month? | In next month? |
| Feb-2024 | 001 | No | Yes |
| Mar-2024 | 001 | Yes | Yes |
| Apr-2024 | 001 | Yes | No |
| Feb-2024 | 002 | No | No |
| Feb-2024 | 003 | No | Yes |
| Mar-2024 | 003 | Yes | No |
Solved! Go to Solution.
hello @threw001
i assumed you only have 'Month-Year' and 'ID' column as your original table. Additionally, i assumed you want to make both 'In Prev Month?' and 'In Next Month?' as column (not measure).
create a new calculated column for 'In Prev Month?' with following DAX.
In Prev Month? =
var _Value =
MAXX(
FILTER(
'Table',
'Table'[Month-Year]<EARLIER('Table'[Month-Year])&&
'Table'[ID]=EARLIER('Table'[ID])
),
'Table'[Month-Year]
)
Return
IF(
not ISBLANK(_Value),
"Yes",
"No"
)
In Next Month? =
var _Value =
MAXX(
FILTER(
'Table',
'Table'[Month-Year]>EARLIER('Table'[Month-Year])&&
'Table'[ID]=EARLIER('Table'[ID])
),
'Table'[Month-Year]
)
Return
IF(
not ISBLANK(_Value),
"Yes",
"No"
)
hello @threw001
here is the DAX for 'In Prev Month'.
In Prev Month =
var _Value =
MAXX(
FILTER(
'Table 3',
'Table 3'[Month-Year]<EARLIER('Table 3'[Month-Year])&&
'Table 3'[ID]=EARLIER('Table 3'[ID])
),
'Table 3'[Month-Year]
)
Return
IF(
EOMONTH('Table 3'[Month-Year],-1)=EOMONTH(_Value,0),
"Yes",
"No"
)
hello @threw001
i assumed you only have 'Month-Year' and 'ID' column as your original table. Additionally, i assumed you want to make both 'In Prev Month?' and 'In Next Month?' as column (not measure).
create a new calculated column for 'In Prev Month?' with following DAX.
In Prev Month? =
var _Value =
MAXX(
FILTER(
'Table',
'Table'[Month-Year]<EARLIER('Table'[Month-Year])&&
'Table'[ID]=EARLIER('Table'[ID])
),
'Table'[Month-Year]
)
Return
IF(
not ISBLANK(_Value),
"Yes",
"No"
)
In Next Month? =
var _Value =
MAXX(
FILTER(
'Table',
'Table'[Month-Year]>EARLIER('Table'[Month-Year])&&
'Table'[ID]=EARLIER('Table'[ID])
),
'Table'[Month-Year]
)
Return
IF(
not ISBLANK(_Value),
"Yes",
"No"
)
Hi @Irwan
My apologies - I just need a deep dive test and it is not behaving as per expected. Most likely because I did not make this clear in the description.
I have a below example. Client ID 015 initially seen in Jun-2024, not seen in Jul-2024 but again in Aug-2024, I would have expected "In Next Month" field to flag as No as the Next Calendar Month is July and not Aug. Similarly I would expect the Aug-2024 entry, column "In Prev month" to flag as No as it is not the prior month, it was in Jun-2024. Is there anyway to adjust the logic to account for this?
Thank you 🙂
| Month-Year | Client ID | In Prev month | In Next Month |
| Jun-2024 | 015 | No | Yes |
| Aug-2024 | 015 | Yes | No |
hello @threw001
did you not get the expected result in your original data?
the DAX seems work in this sample data without any changes in DAX.
In Next Month =
var _Value =
MAXX(
FILTER(
'Table 2',
'Table 2'[Month-Year]>EARLIER('Table 2'[Month-Year])&&
'Table 2'[Client ID]=EARLIER('Table 2'[Client ID])
),
'Table 2'[Month-Year]
)
Return
IF(
not ISBLANK(_Value),
"Yes",
"No"
)
In Prev Month =
var _Value =
MAXX(
FILTER(
'Table 2',
'Table 2'[Month-Year]<EARLIER('Table 2'[Month-Year])&&
'Table 2'[Client ID]=EARLIER('Table 2'[Client ID])
),
'Table 2'[Month-Year]
)
Return
IF(
not ISBLANK(_Value),
"Yes",
"No"
)
Hi @Irwan You're DAX example is also not behaving in the same way I would expect it to.
Hope this makes sense?
Thanks
hello @threw001
i see, so you have jump in date in your original data.
so we can adjust in the if statement.
please try using these following DAXs.
In Prev Month =
var _Value =
MAXX(
FILTER(
'Table 2',
'Table 2'[Month-Year]<EARLIER('Table 2'[Month-Year])&&
'Table 2'[Client ID]=EARLIER('Table 2'[Client ID])
),
'Table 2'[Month-Year]
)
Return
IF(
EOMONTH('Table 2'[Month-Year],-1)=EOMONTH(_Value,0),
"Yes",
"No"
)
In Next Month =
var _Value =
MAXX(
FILTER(
'Table 2',
'Table 2'[Month-Year]>EARLIER('Table 2'[Month-Year])&&
'Table 2'[Client ID]=EARLIER('Table 2'[Client ID])
),
'Table 2'[Month-Year]
)
Return
IF(
EOMONTH('Table 2'[Month-Year],1)=EOMONTH(_Value,0),
"Yes",
"No"
)
Hi @Irwan
Thank you so much for your help..
Yes thats correct.
I tried the new code you sent over however the 'In Next Month' calculated column is not behaving as expected.
So I have ID 25 - It appears from January 2024, every month up until October 2024. In the month of April 2024, the 'In Next Month' column is flagging 'No' although it definitely appears in May 2024. Hope you can recreate this..
Thanks
Hi @Irwan
To provide more info please use the below source:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdC7DcAwCIThXagtBfwAexbL+6+RRClC8UtUn664Y29Ru56rWrsUUbUhp3xaURtqRx2ojhqoE3WRmqLiNuNtWQP7Bm1rTtmkKTvxD8tp8a+576vnBg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Month-Year" = _t, ID = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Month-Year", type date}, {"ID", type text}})
in
#"Changed Type"In Prev Month =
var _Value =
MAXX(
FILTER(
'Month-Year Client ID',
'Month-Year Client ID'[Month-Year]<EARLIER('Month-Year Client ID'[Month-Year])&&
'Month-Year Client ID'[ID]=EARLIER('Month-Year Client ID'[ID])
),
'Month-Year Client ID'[Month-Year]
)
Return
IF(
EOMONTH('Month-Year Client ID'[Month-Year],-1)=EOMONTH(_Value,0),
"Yes",
"No"
)In Next Month =
var _Value =
MAXX(
FILTER(
'Month-Year Client ID',
'Month-Year Client ID'[Month-Year]>EARLIER('Month-Year Client ID'[Month-Year])&&
'Month-Year Client ID'[ID]=EARLIER('Month-Year Client ID'[ID])
),
'Month-Year Client ID'[Month-Year]
)
Return
IF(
EOMONTH('Month-Year Client ID'[Month-Year],1)=EOMONTH(_Value,0),
"Yes",
"No"
)Output Table:
Thanks
@Irwan - you are a legend. Thank you so much for all your help with this..
"In Next Month" works perfectly now!
I still have issues with "In Prev Month".
I used same source code as above just changed the calculated column with your new code
All lines highlighted in yellow should say "No". For example ID 0017, the first month it appears is February 2024 however "In Prev Month" field, it says "Yes" when it should say "No".
Similarly ID 0017 appears again in June 2024, although 0017 appeared in February, this should still "No" as it was back in February 2024 not May 2024 (actual Prev Month)
hello @threw001
hmm.. not sure why you got different result.
i am literally used the same data from before but added more date as your sample data.
i think you are using Text format on 'ID'.
make sure 'Month-Year' is Date format and 'ID' is Number format (Number format will not show those two zero in front as in your sample data).
Hope this will help.
Thank you.
Hi @Irwan - thank you so much again
I have changed ID to Number type however still the same 😞 Are you able to re-share the calculated "In Prev Month" column you are using please? It may be something I've done..
Thanks
hello @threw001
here is the DAX for 'In Prev Month'.
In Prev Month =
var _Value =
MAXX(
FILTER(
'Table 3',
'Table 3'[Month-Year]<EARLIER('Table 3'[Month-Year])&&
'Table 3'[ID]=EARLIER('Table 3'[ID])
),
'Table 3'[Month-Year]
)
Return
IF(
EOMONTH('Table 3'[Month-Year],-1)=EOMONTH(_Value,0),
"Yes",
"No"
)
Hi @Irwan - definitely something I did as it works perfectly now! Thank you so so much for all your help and effort.
It is much appreciated
hello @threw001
is this what you are looking for?
i assumed 'In Prev Month' works for you but here is the DAX just incase.
In Prev Month =
var _Value =
MAXX(
FILTER(
'Table 3',
'Table 3'[Month-Year]<EARLIER('Table 3'[Month-Year])&&
'Table 3'[ID]=EARLIER('Table 3'[ID])
),
'Table 3'[Month-Year]
)
Return
IF(
EOMONTH('Table 3'[Month-Year],-1)=EOMONTH(_Value,0),
"Yes",
"No"
)
In Next Month =
var _Value =
MINX(
FILTER(
'Table 3',
'Table 3'[Month-Year]>EARLIER('Table 3'[Month-Year])&&
'Table 3'[ID]=EARLIER('Table 3'[ID])
),
'Table 3'[Month-Year]
)
Return
IF(
EOMONTH('Table 3'[Month-Year],1)=EOMONTH(_Value,0),
"Yes",
"No"
)
Absolutely perfect - thank you so much for your help! Works a treat 🙂
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 80 | |
| 49 | |
| 35 | |
| 31 | |
| 30 |