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
intrasight
Helper IV
Helper IV

Aggregating records with a date column to week, month, and quarter with SQL Server DirectConnect

Is this possible? Is there a standard M pattern for this? I didn't find anything here or Googling, but perhaps I'm asking the question the wrong way. I have daily data and I wish to group/aggregate by week or month or quarter. I was assuming that this would be easy in Power BI using M, but since I've found no samples, I am thinking perhaps not.

 

1 ACCEPTED SOLUTION

@intrasight

 

The errors is due to the limitation of DirectQuery mode. Since you're using SQL Server, the requirement can be easily achieved by queries as below. You can apply those queries individually when "get data".

select year(orderdate)[year],datepart(week,orderdate) [week],sum(sales) totalSales from orders
group by year(orderdate),datepart(week,orderdate)

select year(orderdate) [year],datepart(quarter,orderdate) [quarter],sum(sales) totalSales  from orders
group by year(orderdate),datepart(quarter,orderdate)

select dateadd(month,datediff(month,0,orderdate),0) [month] ,sum(sales) totalSales from orders
group by dateadd(month,datediff(month,0,orderdate),0)

Capture.PNG

Capture.PNG

View solution in original post

2 REPLIES 2
intrasight
Helper IV
Helper IV

I just tried adding this expression:

 

#"AddMonth" = Table.AddColumn(dbo_InventoryView, "Month", each Date.StartOfMonth([StorageDate]), type date)

 

But I get the error:

 

"This step results in a query that is not supported in DirectQuery mode"

@intrasight

 

The errors is due to the limitation of DirectQuery mode. Since you're using SQL Server, the requirement can be easily achieved by queries as below. You can apply those queries individually when "get data".

select year(orderdate)[year],datepart(week,orderdate) [week],sum(sales) totalSales from orders
group by year(orderdate),datepart(week,orderdate)

select year(orderdate) [year],datepart(quarter,orderdate) [quarter],sum(sales) totalSales  from orders
group by year(orderdate),datepart(quarter,orderdate)

select dateadd(month,datediff(month,0,orderdate),0) [month] ,sum(sales) totalSales from orders
group by dateadd(month,datediff(month,0,orderdate),0)

Capture.PNG

Capture.PNG

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