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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
dashmarley11
Helper III
Helper III

Datepart for Report Builder

In MS Report Builder, I'm trying to create a new Calculated Field (StartActAccrual) that renders the exact same results as this SQL Declare statement:

 

DECLARE @StartActAccrual FLOAT = 1.0 * Day(EOMONTH(@StartTapeDate,0)) / (SELECT CASE WHEN DAY(EOMONTH(DATEFROMPARTS(YEAR(@StartTapeDate),2,1))) = 29 THEN 366 ELSE 365 END)

 

 

1 ACCEPTED SOLUTION
burakkaragoz
Community Champion
Community Champion

Hi @dashmarley11 ,

 

For MS Report Builder, you can mimic that SQL logic in a calculated field, but the syntax will be a bit different since Report Builder uses Expressions (which are more like VB.NET). Here’s one way you could do it:

If your goal is to calculate the number of days in the month of @StartTapeDate divided by either 366 or 365 (based on if the year is a leap year), try something like this in your calculated field expression:

vb
 
=Day(DateAdd("d", -1, DateAdd("m", 1, Fields!StartTapeDate.Value))) / 
    (IIf(Day(DateSerial(Year(Fields!StartTapeDate.Value), 2, 29)) = 29, 366, 365))
  • The first part: Day(DateAdd("d", -1, DateAdd("m", 1, ...))) gets the last day of the month (like EOMONTH in SQL).
  • The IIf checks if Feb 29 exists for the year (so, leap year logic), then picks 366 or 365.

Just make sure to replace Fields!StartTapeDate.Value with your actual field name if it’s different.

Let me know if you need help fitting this into your report or if you get any errors!

If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.

Translation & text editing supported by AI

View solution in original post

1 REPLY 1
burakkaragoz
Community Champion
Community Champion

Hi @dashmarley11 ,

 

For MS Report Builder, you can mimic that SQL logic in a calculated field, but the syntax will be a bit different since Report Builder uses Expressions (which are more like VB.NET). Here’s one way you could do it:

If your goal is to calculate the number of days in the month of @StartTapeDate divided by either 366 or 365 (based on if the year is a leap year), try something like this in your calculated field expression:

vb
 
=Day(DateAdd("d", -1, DateAdd("m", 1, Fields!StartTapeDate.Value))) / 
    (IIf(Day(DateSerial(Year(Fields!StartTapeDate.Value), 2, 29)) = 29, 366, 365))
  • The first part: Day(DateAdd("d", -1, DateAdd("m", 1, ...))) gets the last day of the month (like EOMONTH in SQL).
  • The IIf checks if Feb 29 exists for the year (so, leap year logic), then picks 366 or 365.

Just make sure to replace Fields!StartTapeDate.Value with your actual field name if it’s different.

Let me know if you need help fitting this into your report or if you get any errors!

If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.

Translation & text editing supported by AI

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.

Top Solution Authors