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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Ashik008
Frequent Visitor

Sale in quarter

Hi all,

Please help to find a sql query to calculate the total sales in quarter 

table as follow 

ProductMonth numberyearsale
A220221000
B220222000
c120221000
B420223000
A120221000
c620222000

 

result im looking for 

 

ProductQuarterSale
AQuarter15000
BQuarter12000
CQuarter11000
BQuarter23000
CQuarter22000

please help

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Ashik008 ,

Please try to create a new column with below dax formula:

Quarter =
VAR cur_year = 'Table'[year]
VAR cur_month = 'Table'[Month number]
VAR _date =
    DATE ( cur_year, cur_month, 1 )
RETURN
    "Quarter" & QUARTER ( _date )

Add a table visual with fields:

vbinbinyumsft_0-1692669819755.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Ashik008 ,

Please try to create a new column with below dax formula:

Quarter =
VAR cur_year = 'Table'[year]
VAR cur_month = 'Table'[Month number]
VAR _date =
    DATE ( cur_year, cur_month, 1 )
RETURN
    "Quarter" & QUARTER ( _date )

Add a table visual with fields:

vbinbinyumsft_0-1692669819755.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Ashik008 , I assume you need power bi solution

Create a date with year and month

 

Date = Date([Year], [Month],1)

 

Create a date Table like

 

Calendar = Addcolumns(calendar(date(2012,01,01), date(2024,12,31) ), "Month no" , month([date])
, "Year", year([date])
, "Month Year", format([date],"mmm-yyyy")
, "Month year sort", year([date])*100 + month([date])
, "Qtr Year", format([date],"yyyy-\QQ")
, "Qtr", quarter([date])
, "Month",FORMAT([Date],"mmmm")
, "Month sort", month([DAte])
, "FY Year", if( Month(([DAte])) <7 , year(([DAte]))-1 ,year(([DAte])))
, "Is Today" ,if([Date]=TODAY(),"Today",[Date]&"")
,"Day of Year" , datediff(date(year([DAte]),1,1), [Date], day)+1
, "Month Type", Switch( True(),
eomonth([Date],0) = eomonth(Today(),-1),"Last Month" ,
eomonth([Date],0)= eomonth(Today(),0),"This Month" ,
Format([Date],"MMM-YYYY") )
,"Year Type" , Switch( True(),
year([Date])= year(Today()),"This Year" ,
year([Date])= year(Today())-1,"Last Year" ,
Format([Date],"YYYY")
)
)

 

and join with date table

 

and use qtr column from date and sum(sales) from your table

 

You can create the different formats of quarters as per need in the date table

 

https://community.powerbi.com/t5/Community-Blog/Creating-Financial-Calendar-Decoding-Date-and-Calend...
https://medium.com/chandakamit/cheat-sheet-calendar-of-any-standard-month-just-one-variable-apart-5e...
https://amitchandak.medium.com/cheat-sheet-power-query-financial-year-calendar-5ceaacb520f1

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.