Forum Discussion

FatBlackCat30's avatar
FatBlackCat30
Microsoft Employee
5 years ago
Solved

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

 

  • Hi FatBlackCat30 ,

     

    Try this measure,

     

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

     


    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

  • 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-Calendar-1-5-Power/ba-p/1187441

3 Replies

  • Nathaniel_C's avatar
    Nathaniel_C
    Community Champion

    Hi FatBlackCat30 ,

     

    Try this measure,

     

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

     


    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

  • 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-Calendar-1-5-Power/ba-p/1187441