Forum Discussion

kl8818's avatar
kl8818
Frequent Visitor
2 years ago
Solved

Syntax Error for Quarter Date Variable

Hi - could someone explain what was done incorrectly with this measurement? Power BI is stating my syntax for 'StartofQuarter' is incorrect.

Agree / Strongly Agree QTR (%) =
VAR CurrentDate = TODAY()
VAR StartofQuarter =
STARTOFQUARTER(CurrentDate)
VAR EndofQuarter =
ENDOFQUARTER(CurrentDate)

RETURN
CALCULATE('Level 1'[Agree / Strongly Agree (%)],
FILTER('Level 1', 'Level 1'[From Date] >= StartofQuarter && 'Level 1'[From Date] <= EndofQuarter))
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi kl8818 ,

     

    At my knowledge, the STARTOFQUARTER function expects a date column as an argument, not a single date value.

    Please try something like this

    Agree / Strongly Agree QTR (%) =
    
    VAR CurrentDate = TODAY()
    
    VAR CurrentYear = YEAR(CurrentDate)
    
    VAR CurrentQuarter = QUARTER(CurrentDate)
    
    
    
    VAR _StartOfQuarter =
    
        SWITCH(
    
            TRUE(),
    
            CurrentQuarter = 1, DATE(CurrentYear, 1, 1),
    
            CurrentQuarter = 2, DATE(CurrentYear, 4, 1),
    
            CurrentQuarter = 3, DATE(CurrentYear, 7, 1),
    
            CurrentQuarter = 4, DATE(CurrentYear, 10, 1)
    
        )
    
    RETURN ***

     

    Best Regards,

    Wearsky

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi kl8818 ,

     

    At my knowledge, the STARTOFQUARTER function expects a date column as an argument, not a single date value.

    Please try something like this

    Agree / Strongly Agree QTR (%) =
    
    VAR CurrentDate = TODAY()
    
    VAR CurrentYear = YEAR(CurrentDate)
    
    VAR CurrentQuarter = QUARTER(CurrentDate)
    
    
    
    VAR _StartOfQuarter =
    
        SWITCH(
    
            TRUE(),
    
            CurrentQuarter = 1, DATE(CurrentYear, 1, 1),
    
            CurrentQuarter = 2, DATE(CurrentYear, 4, 1),
    
            CurrentQuarter = 3, DATE(CurrentYear, 7, 1),
    
            CurrentQuarter = 4, DATE(CurrentYear, 10, 1)
    
        )
    
    RETURN ***

     

    Best Regards,

    Wearsky