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

View all the Fabric Data Days sessions on demand. View schedule

Reply
Anonymous
Not applicable

DAX formula for counting number of days in the quarrter

I'm new to Power BI. What's the DAX formula to calculate the number of days in the current quarter assuming 10/01/18 is the start of the quarter and today? It would like the formula to always calculate the beginning of the quarter and end of the quarter is today (QTD). I've attched a simple table below for reference.

 

DateWater ProductionDay CountQTD Avg
10/1/20181001 
10/2/2018201 
10/3/20183001 
10/4/20184001 
10/5/20181011 
10/6/20183031 
10/7/20183061 
10/8/20184011 
10/9/20181021 
10/10/20183091 
10/11/20183121 
10/12/20184021 
10/13/20181031 
10/14/20183151 
10/15/20183181 
10/16/20184031 
10/17/20181041 
10/18/20183211 
10/19/20183241 
10/20/20184041 
10/21/20181051 
10/22/20183271 
10/23/20183301 
10/24/20184051 
10/25/20181061 
10/26/20183331 
10/27/20183361 
10/28/20184061 
10/29/20181071 
10/30/20183391 
10/31/20183421 
11/1/20184071 
11/2/20181081 
11/3/20183451 
11/4/20183481 
11/5/20184081 
11/6/20181091 
11/7/20183511 
11/8/20183541 
11/9/20184091 
Total                       11,323                40     283.08
 (a)(b)=(a)/(b)
4 REPLIES 4
Anonymous
Not applicable

@Anonymous,

Please create the following columns in your table and if the DAX below doesn't help, please post expected result based on above sample data here.

start of quarter = STARTOFQUARTER(Table[Date])  
daynumber = DATEDIFF(Table[start of quarter],Table[Date],DAY)
Column = DATEDIFF(Table[start of quarter],TODAY(),DAY)

1.PNG

Regards,
Lydia

Anonymous
Not applicable

Lydia - thanks for the feedback.  however, I couldn't get the "daynumber" to work.  see error.

 

 Capture.PNG

Anonymous
Not applicable

@Anonymous,

Do you create calculated column? If so, please change your formula to the following:

daynumber = DATEDIFF(Table[start of quarter],RELATED('Calendar'[Date]),DAY)


If you are creating measure, please use DAX below.

daynumber = DATEDIFF([start of quarter],max('Calendar'[Date]),DAY)




Regards,

 

 Lydia

Greg_Deckler
Community Champion
Community Champion

OK, I have a couple of formulas for you, one is a column and the other is a measure.

 

Column:

QTD Avg = 
VAR __currentYear = YEAR([Date])
VAR __currentQuarter = [Quarter]
VAR __table = FILTER(ALL(Table5),YEAR([Date])=__currentYear && [Quarter]=__currentQuarter && [Date]<=EARLIER([Date]))
RETURN
//DIVIDE(SUMX(__table,[Water Production]),COUNTX(__table,[Date]),0)
AVERAGEX(__table,[Water Production])

Measure:

QTD Avg Measure = 
VAR __currentYear = YEAR(MAX([Date]))
VAR __currentQuarter = MAX([Quarter])
VAR __currentDate = MAX([Date])
VAR __table = FILTER(ALL(Table5),YEAR([Date])=__currentYear && [Quarter]=__currentQuarter && [Date]<=__currentDate)
RETURN
//DIVIDE(SUMX(__table,[Water Production]),COUNTX(__table,[Date]),0)
AVERAGEX(__table,[Water Production])

Now, for the measure in a full scenario you will likely run into issues the the total so refer to this Quick Measure to resolve that

https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

 

And, not sure about the whole TODAY thing but you could just replace __currentDate with = TODAY().



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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