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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
FatBlackCat30
Employee
Employee

Return text value based off condition

Hi all,

 

I am trying to create a DAX mesure that will return the current quarter. my data looks like this:

 

Ive tried a bunch of different ways but nothing is working. the Dax would return the QTR of the latest date. so since the latested date is this data set is 11/25/20 the result should be Q2. what is the best approach to accomplish this? 

 

thank you!!

 

dateQTRUsers
10/30/2020Q1105
10/31/2020Q1515
11/1/2020Q25415
11/2/2020Q2545
11/3/2020Q25645
11/4/2020Q25454
11/5/2020Q2545
11/6/2020Q26458
11/7/2020Q23908
11/8/2020Q23661
11/9/2020Q23414
11/10/2020Q23167
11/11/2020Q22920
11/12/2020Q22673
11/13/2020Q22426
11/14/2020Q22179
11/15/2020Q21932
11/16/2020Q21685
11/17/2020Q21438
11/18/2020Q21191
11/19/2020Q2944
11/20/2020Q2697
11/21/2020Q2450
11/22/2020Q2203
11/23/2020Q21548
11/24/2020Q2125
11/25/2020Q212588

 

2 ACCEPTED SOLUTIONS
Nathaniel_C
Super User
Super User

Hi @FatBlackCat30 ,

 

Try this measure,

 

Latest QTR = 


CALCULATE(MAX('Table'[QTR]),Filter(all('Table'),'Table'[date]=MAX('Table'[date])))

 

q2.PNG
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

amitchandak
Super User
Super User

@FatBlackCat30 , if you want to select a date(slicer) datesqtd can help. If you do want to select then stop your date calendar on today.

 

With date calendar and date in slicer

QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(('Date'[Date])))
Last QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],-1,QUARTER)))

Last complete QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD( ENDOFQUARTER(dateadd('Date'[Date],-1,QUARTER))))
Last to last QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],-2,QUARTER)))

 

Else you need qtr start date in the calendar

Try like

 

Measure =
var _min = minx(allselected('Date') , 'Date'[Qtr Start Date]) //refer to blog to get this
var _min = maxx(allselected('Date') , 'Date'[Date])
return
calculate(countrows('Table'), Filter('Date', 'Date'[Date] >=_min && 'Date'[Date] <=_max ))


Measure =
var _min = minx(allselected('Date') , 'Date'[Qtr Start Date]) //refer to blog to get this
var _min = maxx(allselected('Date') , 'Date'[Date])
return
calculate(countrows('Table'), Filter('Table', 'Table'[Date] >=_min && 'Table'[Date] <=_max ))

 

For Qtr Start Date

Creating Financial Calendar - From Any Month
https://community.powerbi.com/t5/Community-Blog/Creating-Financial-Calendar-Decoding-Date-and-Calend...

View solution in original post

3 REPLIES 3
FatBlackCat30
Employee
Employee

thank you @Nathaniel_C  & @amitchandak  both exellent solutions. I almost had it working, I just missed a small part

amitchandak
Super User
Super User

@FatBlackCat30 , if you want to select a date(slicer) datesqtd can help. If you do want to select then stop your date calendar on today.

 

With date calendar and date in slicer

QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(('Date'[Date])))
Last QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],-1,QUARTER)))

Last complete QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD( ENDOFQUARTER(dateadd('Date'[Date],-1,QUARTER))))
Last to last QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],-2,QUARTER)))

 

Else you need qtr start date in the calendar

Try like

 

Measure =
var _min = minx(allselected('Date') , 'Date'[Qtr Start Date]) //refer to blog to get this
var _min = maxx(allselected('Date') , 'Date'[Date])
return
calculate(countrows('Table'), Filter('Date', 'Date'[Date] >=_min && 'Date'[Date] <=_max ))


Measure =
var _min = minx(allselected('Date') , 'Date'[Qtr Start Date]) //refer to blog to get this
var _min = maxx(allselected('Date') , 'Date'[Date])
return
calculate(countrows('Table'), Filter('Table', 'Table'[Date] >=_min && 'Table'[Date] <=_max ))

 

For Qtr Start Date

Creating Financial Calendar - From Any Month
https://community.powerbi.com/t5/Community-Blog/Creating-Financial-Calendar-Decoding-Date-and-Calend...

Nathaniel_C
Super User
Super User

Hi @FatBlackCat30 ,

 

Try this measure,

 

Latest QTR = 


CALCULATE(MAX('Table'[QTR]),Filter(all('Table'),'Table'[date]=MAX('Table'[date])))

 

q2.PNG
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.