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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Can I switch the Date Format of a field based on a logic, if date is within a month, then as Quarter

How can I switch Date Format for a field in Paginated report based on a logic.

The logic would be as follows:

  • (Finish Date – Current Date) > 3 Months – Display Finish Date as a Quarter (i.e. Q1.2022)
  • (Finish Date – Current Date) <= 3 Months and (Finish Date – Current Date) > 1 Month – Display Finish Date as Month (i.e. February, 2022)
  • (Finish Date – Current Date) <= 1 Month – Display Finish Date as Date (i.e. 2/15/2022)

My current expression for that field is as below-

=FormatDateTime(Fields!Finish_Date.Value, Microsoft.VisualBasic.DateFormat.ShortDate)

 

Thank you in advance.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

Only one data type can exist in the same column, and the calculated column [Column] has data of both Date type ([Finish Date]) and Text type ( FORMAT ( [Finish Date], "MMMM, YYYY" ) and FORMAT ( [Finish Date], "QQ-YYYY") ), so it reported variant data-type error... You can change its formula to the following one:

DAX Fridays! #148: CONVERT and resolve variant data-type error

Column =
VAR _1 =
DATEDIFF (
TODAY (),
'Consolidated In Progress Status Report'[Finish Date],
MONTH
)
RETURN
SWITCH (
TRUE (),
_1 < 1, FORMAT ( [Finish Date], "MM/DD/YYYY" ),
_1 <= 3, FORMAT ( [Finish Date], "MMMM, YYYY" ),
_1 > 3, FORMAT ( [Finish Date], "QQ-YYYY" )
)

yingyinr_0-1632735416762.png

Best Regards

View solution in original post

10 REPLIES 10
HotChilli
Super User
Super User

The comma at the end requires a default value afterwards OR delete the comma if a default case is not required

Anonymous
Not applicable

Thank you for catching that. I made the change and now I am getting the "Expressions that yield variant data-type cannot be used to define calculated columns" error. 

 

bverma_0-1632415176501.png

 

I am not sure if you can use calculated column to solve my original problem. Maybe, I need to do something within the Paginated Report (Finish Date Query) to achieve this.

Anonymous
Not applicable

Hi @Anonymous ,

Only one data type can exist in the same column, and the calculated column [Column] has data of both Date type ([Finish Date]) and Text type ( FORMAT ( [Finish Date], "MMMM, YYYY" ) and FORMAT ( [Finish Date], "QQ-YYYY") ), so it reported variant data-type error... You can change its formula to the following one:

DAX Fridays! #148: CONVERT and resolve variant data-type error

Column =
VAR _1 =
DATEDIFF (
TODAY (),
'Consolidated In Progress Status Report'[Finish Date],
MONTH
)
RETURN
SWITCH (
TRUE (),
_1 < 1, FORMAT ( [Finish Date], "MM/DD/YYYY" ),
_1 <= 3, FORMAT ( [Finish Date], "MMMM, YYYY" ),
_1 > 3, FORMAT ( [Finish Date], "QQ-YYYY" )
)

yingyinr_0-1632735416762.png

Best Regards

HotChilli
Super User
Super User

Yes, there is an error in the code given to you.  I have faith in you to make the fix.  Start at the beginning of the squiggly red line.

Anonymous
Not applicable

I think I am very close. I just have one final error on the Switch syntax (that I need to figure out)

bverma_0-1632338095019.png

 

Column =
var _1 = datediff(TODAY(), 'Consolidated In Progress Status Report'[Finish Date] , Month)
return
Switch( True() ,
_1< 1, [Finish Date],
_1< 3, format([Finish Date], "MMMM, YYYY"),
format([Finish Date], "QQ-YYYY"),
)
HotChilli
Super User
Super User

You've copied the code verbatim but you need to create the column (with a name) and then put the code in.  

-1 is a variable which should be declared within the column.  That's why you're getting syntax errors.

Anonymous
Not applicable

@HotChilli Thank you for taking a look. I made some change (per your comment). I am getting "Too many arguments were passed" error now.

 

2021-09-22 14_21_58-StatusReport - Power BI Desktop.png

 

My update code is"

Column =
var _1 = datediff(TODAY(), 'Consolidated In Progress Status Report'[Finish Date] , Month)
return
Switch( True() ,
_1< 1, [Finish Date],
_1< 3, format([Finish Date], "MMMM, YYYY",
format([Finish Date], "QQ-YYYY"
)))
amitchandak
Super User
Super User

@Anonymous , a new column

var _1 = datediff(Current Date, Finish Date , Month)

return

Switch( True() ,

_1< 1, [Finish Date],

_1 <3, format([Finish Date], "MMMM, YYYY",

format([Finish Date], "QQ-YYYY"

)

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
Anonymous
Not applicable

@amitchandak I am still getting the "Arugment '8' in SWITCH fucntion is required" error, is there in the DAX code below-

 

Column =
var _1 = datediff(TODAY(), 'Consolidated In Progress Status Report'[Finish Date] , Month)
return
Switch(True() ,
_1< 1, [Finish Date],
_1<= 3, format([Finish Date], "MMMM, YYYY"),
_1> 3, format([Finish Date], "QQ-YYYY"),
)

 

bverma_0-1632402267538.png

 

Thank you for your time.

Anonymous
Not applicable

@amitchandak  Thank you for your quick response. So, I created a new calculated column on the same table (where the Finish date exists). I replaced the Current Date to TODAY (). But I am getting the following error (not sure what I am doing wrong)-

 

My updated query is-

 

var _1 = datediff(TODAY(), 'Consolidated In Progress Status Report'[Finish Date], month)
return
Switch( True() ,
_1< 1, [Finish Date],
_1 <3, format([Finish Date], "MMMM, YYYY",
format([Finish Date], "QQ-YYYY"
)

 

2021-09-22 12_37_16-StatusReport - Power BI Desktop.png

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors