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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Calculating Days Past Dynamically

GOAL: Calculate appropriate days_past as  the year progresses.
 
Current measure code:
days_past = datediff(DATE(YEAR([year_desired]),1,1),DATE(YEAR([year_desired]),MONTH(MAX('Calendar'[Date])),DAY(EOMONTH(MAX('Calendar'[Date]),0))+1),DAY)
 
However, this currently calculates the days past in the year to the end of the month.
Example: If we were at 11/03/2022, the days past would return 333. I want it to return the actual days past (306 days).
 
So, I tried:
days_past = datediff(DATE(YEAR([year_desired]),1,1),DATE(YEAR([year_desired]),MONTH(MAX('Calendar'[Date])),DAY(MAX('Calendar'[Date]))),DAY)
 
But this then ruins my historical days past. So, when I look back at days past in March, it would show days past since 03/03/2022. Whereas, here, I want it to show  days past since 03/31/2022. So, I want the end-of-month logic for months that have already gone by, but want the current days past in the current month.
 
Seems fairly simple, but I am having issues making it work with IF statements. Not super familiar with loops in DAX. I have more background with Python.
 
Thanks for help,
Joel
3 REPLIES 3
v-xiaosun-msft
Community Support
Community Support

Hi @Anonymous ,

 

I wonder whether I understand your requirement correctly. Do you want to return the number of days from the beginning of the year to that date for each date in the Calendar as below?

Column =
DATEDIFF ( DATE ( YEAR ( 'Calendar'[date] ), 1, 1 ), 'Calendar'[date], DAY )

Final output:

vxiaosunmsft_0-1669796127833.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.  

 

Best Regards,
Community Support Team _ xiaosun

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

MonthsDays Past  Last Refresh Date
1/1/202231  11/20/2022
2/1/202259   
3/1/202290   
    
11/1/202220 + prior days   
12/1/2022    

 

See example table. I don't have day logic for much of my data, but do have a specific refresh_date. So, for past months, I want the days through the end of the month summed. Then, for the current month, I want the days in the prior months + the datediff between the current month start date (in this example, 11/1/2022) and the refresh date (11/20/2022).

 

Does this make sense?

 

Thanks for your help :),

Joel

 

Anonymous
Not applicable

Any update on the above?

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 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.