Search code examples
powerbidax

get the current quarter in DAX


I have a code as below. The month May should be in Quarter 1 = QUARTER(TODAY()) but QUARTER('Calendar'[Date]) seems not producing the same output. Is there a reason for that? many thanks in advance.

 get_current_quarter = 

IF(
    AND(
    QUARTER(TODAY()) = QUARTER('Calendar'[Date]),
    YEAR(TODAY()) = YEAR('Calendar'[Date])
    ),
    "Yes",
    "No"
)

Solution

  • Based on the answer I provided here, you can add a calculated column where you consider that your fiscal year starts from May of each year :

    IsCurrentQuarter = 
    VAR CurrentDate = TODAY()
    VAR CurrentMonth = MONTH(CurrentDate)
    VAR CurrentYear = YEAR(CurrentDate)
    VAR CurrentFiscalYear = IF(CurrentMonth >= 5, CurrentYear, CurrentYear - 1)
    VAR CurrentFiscalQuarter = SWITCH(
        TRUE(),
        CurrentMonth >= 5 && CurrentMonth <= 7, 1,
        CurrentMonth >= 8 && CurrentMonth <= 10, 2,
        CurrentMonth >= 11 && CurrentMonth <= 1, 3,
        CurrentMonth >= 2 && CurrentMonth <= 4, 4
    )
    RETURN
        IF (
            [Fiscal Year] = CurrentFiscalYear &&
            [Fiscal Quarter] = CurrentFiscalQuarter,
            "Yes",
            "No"
        )
    

    enter image description here

    Same for June and July :

    enter image description here

    enter image description here

    Different for August which belongs to the 2nd quarter of the fiscal year and is not current comparing to the current date :

    enter image description here