Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hello,
I have a date table which only has Month level data ( year, quarter, Month). Based on the filter, need to calculate the number of weeks.
Single year will be chosen so, can start the week count from start of year. User can choose month from different quarters also. Or can choose a full quarter. If current month is also chosen, only completed week should be considered-Basically upto previous week.
Kindly help to calculate the number of weeks using DAX
Solved! Go to Solution.
Hi @suma2413 ,
Here is my test data and Steps you can try:
Create measures:
startDateOfMonth = STARTOFMONTH('Table'[Year-Month])endDateOfMonth = EOMONTH([startDateOfMonth],0)Sum =
IF(
HASONEFILTER('Table'[Year-Month]),
DATEDIFF([startDateOfMonth],[endDateOfMonth],WEEK),
SUMX('Table',DATEDIFF([startDateOfMonth],[endDateOfMonth],WEEK))
)
Final output
Best regards,
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi @suma2413 ,
Here is my test data and Steps you can try:
Create measures:
startDateOfMonth = STARTOFMONTH('Table'[Year-Month])endDateOfMonth = EOMONTH([startDateOfMonth],0)Sum =
IF(
HASONEFILTER('Table'[Year-Month]),
DATEDIFF([startDateOfMonth],[endDateOfMonth],WEEK),
SUMX('Table',DATEDIFF([startDateOfMonth],[endDateOfMonth],WEEK))
)
Final output
Best regards,
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Thsis helps, But still doesnt provide week count which are complete..Hence I introduced WeekNo and then wrote DAX to calculate only complete weeks.
I would suggest using a proper date table, this will make your life a whole lot easier.
There are some great examples of extended date tables out there that can be created easily in Power Query.
Here is a good article with some steps and a link to the code you can copy and paste.
https://blog.enterprisedna.co/using-the-m-function-to-create-an-extended-power-bi-date-table/
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 13 | |
| 5 | |
| 5 | |
| 3 | |
| 3 |
| User | Count |
|---|---|
| 25 | |
| 10 | |
| 10 | |
| 6 | |
| 6 |