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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
louie_c
Regular Visitor

DAX on Quarters

louie_c_0-1646127480967.png

 

Hi, Inquring on how i can get this following data given quarterly date filters. The catch is:

 

* need to get comparative number of months only when quarter is incomplete.

 

Actual Quarter vs. Last Quarter and Target

 

Actual is say, still as of Jan'22 only.

Target is fully given for entire year already.

 

So when we select Q1 2022

  • Actual should be = Jan'22 (no problem here)
  • Last Quarter should be = Oct'21 only, not summing Oct'21 to Dec'21 since only 1 month data is available for current quarter
  • Target should be = Jan'22, should not include Feb'22 to Mar'22 even data is available since only 1 month data is available for current quarter

Also if we can get lifetime to date based on the selected quarter:

 

Example: Start Date of data is Oct'2017 latest is Jan'2022

When I select:

Q3 2021 Lifetime should be Oct'2017 to Sep'2021 sum

Q4 2021 Lifetime should be Oct'2017 to Dec'2021 sum

Q1 2022 Lifetime should be Oct'2017 to Jan'2022 sum

 

See Illustration.

 

Thanks in advance!

2 ACCEPTED SOLUTIONS
Whitewater100
Solution Sage
Solution Sage

Hello:

You can do a couple of steps:

Create a field in Date Table to show if Qtr Complete:

Completed Qtr =
VAR ThisQtrID =
LOOKUPVALUE(Dates[QuarternYear], Dates[Date], TODAY())
RETURN Dates[QuarternYear] < ThisQtrID
 
Then first measure:
Prev Qtr = CALCULATE([Total Sales], PREVIOUSQUARTER(Dates[Date]))
 
Then last measure:
Previous Qtr =
var PQ = [Prev Qtr]
var QtrComplete = IF(SELECTEDVALUE(Dates[QuarterCompleted]),1,0)
return
IF(QtrComplete = 1,
PQ,
CALCULATE([Total Sales], DATESBETWEEN(Dates[Date], STARTOFQUARTER(Dates[Date]), TODAY())
)
)

View solution in original post

If you want thru EOM prev month vs TODAY on last measure suggested you can use:

 

Previous Qtr =
var PQ = [Prev Qtr]
var QtrComplete = IF(SELECTEDVALUE(Dates[QuarterCompleted]),1,0)
return
IF(QtrComplete = 1,
PQ,
CALCULATE([Total Sales], DATESBETWEEN(Dates[Date], STARTOFQUARTER(Dates[Date]),LASTDATE(PREVIOUSMONTH(Dates[Date])
)
)))

View solution in original post

4 REPLIES 4
Whitewater100
Solution Sage
Solution Sage

Hello:

You can do a couple of steps:

Create a field in Date Table to show if Qtr Complete:

Completed Qtr =
VAR ThisQtrID =
LOOKUPVALUE(Dates[QuarternYear], Dates[Date], TODAY())
RETURN Dates[QuarternYear] < ThisQtrID
 
Then first measure:
Prev Qtr = CALCULATE([Total Sales], PREVIOUSQUARTER(Dates[Date]))
 
Then last measure:
Previous Qtr =
var PQ = [Prev Qtr]
var QtrComplete = IF(SELECTEDVALUE(Dates[QuarterCompleted]),1,0)
return
IF(QtrComplete = 1,
PQ,
CALCULATE([Total Sales], DATESBETWEEN(Dates[Date], STARTOFQUARTER(Dates[Date]), TODAY())
)
)

Thanks. Will check this solution.

If you want thru EOM prev month vs TODAY on last measure suggested you can use:

 

Previous Qtr =
var PQ = [Prev Qtr]
var QtrComplete = IF(SELECTEDVALUE(Dates[QuarterCompleted]),1,0)
return
IF(QtrComplete = 1,
PQ,
CALCULATE([Total Sales], DATESBETWEEN(Dates[Date], STARTOFQUARTER(Dates[Date]),LASTDATE(PREVIOUSMONTH(Dates[Date])
)
)))
amitchandak
Super User
Super User

@louie_c, last three like cumulative

 

example

Cumm Sales = CALCULATE(SUM(Sales[Sales Amount]),filter(allselected('Date'),'Date'[date] <=max('Date'[date])))

 

 

only when qtr is selected

Cumm Sales till last qtr = CALCULATE(SUM(Sales[Sales Amount]),filter(allselected('Date'),'Date'[date] <=eomonth(max('Date'[date]),-3) ))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.