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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Dax for Current Month & Previous Month

Hi,

 

I'm trying to create a calculated colunm that groups dates into one of three values.

 

Current Month - all dates that are in this month

Previous Month - all dates in previous month

Historic - all dates in the past that do not meet the criteria above.

 

Is this even possible? if so how would i go about writing this Dax?

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @Anonymous 

try column

 = 
IF(
AND(MONTH('Table'[DateColumn])=MONTH(today());YEAR('Table'[DateColumn])=YEAR(today()));
"Current Month";
 IF( 
 AND(MONTH('Table'[DateColumn])=MONTH(EOMONTH(today();-1));YEAR('Table'[DateColumn])=YEAR(EOMONTH(today();-1)));
   "Previous Month";
"Historic"
)

its possible also to add check if "future period"

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

4 REPLIES 4
Datagulf
Responsive Resident
Responsive Resident

Hello guys @az38 ,  Ihave decoded the error. the formula is a follows. 

MTD FILTER = 
IF(
MONTH('INV1 Invoice Rows'[DocDate])=MONTH(today())&& YEAR('INV1 Invoice Rows'[DocDate])=YEAR(today()), 
"Current Month",
 IF( 
 MONTH('INV1 Invoice Rows'[DocDate])=MONTH(EOMONTH(today(),-1))&&YEAR('INV1 Invoice Rows'[DocDate])=YEAR(EOMONTH(today(),-1)),
   "Previous Month",
"Historic"
))
az38
Community Champion
Community Champion

Hi @Anonymous 

try column

 = 
IF(
AND(MONTH('Table'[DateColumn])=MONTH(today());YEAR('Table'[DateColumn])=YEAR(today()));
"Current Month";
 IF( 
 AND(MONTH('Table'[DateColumn])=MONTH(EOMONTH(today();-1));YEAR('Table'[DateColumn])=YEAR(EOMONTH(today();-1)));
   "Previous Month";
"Historic"
)

its possible also to add check if "future period"

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Hi @az38,

 

Thanks for this, i've added in the table and colunm names and i keep on getting error messages. Would i need to have a date table?

 

Please see my Dax below.

 

Current Month =
IF(
AND(MONTH('Target data'[date_logged])=MONTH(today());YEAR('Target data'[date_logged])=YEAR(today()));
"Current Month";
IF(
AND(MONTH('Target data'[date_logged])=MONTH(EOMONTH(today();-1));YEAR('Target data'[date_logged])=YEAR(EOMONTH(today();-1)));
   "Previous Month";
"Historic"
)
az38
Community Champion
Community Champion

Hi @Anonymous 

what kind of error?

it works good in my demo-project.

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.