Forum Discussion

awalker2009's avatar
awalker2009
Frequent Visitor
9 months ago
Solved

Power BI - The syntax for ')' is incorrect

Hello, I am trying to enter a formula in DAX to calculate the number of people receiving care support in a particular quarter but keeping getting a syntax error "The syntax for ')' is incorrect" . I have 2 tables:

Data - contains records of people including unique ID and start and end dates of support

Quarters - contains name of Quarter eg 2025/26 Q3, and start and end date of quarter.

The formula is:

Nos Supported = VAR lastqtrdate = MAX(Quarters[Qtr End Date])
var firstqtrdate = min(Quarters[Qtr Start Date])
var result = CALCULATE(COUNTROWS(Data),Data[Start Date]<=lastqtrdate,Data[End Date]>=firstqtrdate)

I'm basically trying to adapt this guy's formula on https://exceleratorbi.com.au/how-many-employees-by-period/ . Has anyone any thoughts?

Thank you

7 Replies

  • awalker2009's avatar
    awalker2009
    Frequent Visitor

    Thanks. I've taken that on board and the formula is working now.

  • Hello awalker2009,

    The error message "The syntax for ')' is incorrect" in your DAX measure is caused by the way filters are being applied within the CALCULATE function. In DAX, filters inside CALCULATE must be valid Boolean expressions or table filters. Expressions such as Data[Start Date] <= lastqtrdate must be wrapped in a FILTER function to be valid.

     

    Please, try it:

    Nos Supported =
    VAR lastqtrdate = MAX(Quarters[Qtr End Date])
    VAR firstqtrdate = MIN(Quarters[Qtr Start Date])
    RETURN
    CALCULATE(
        COUNTROWS(Data),
        FILTER(
            Data,
            Data[Start Date] <= lastqtrdate &&
            Data[End Date] >= firstqtrdate
        )
    )


    CALCULATE – DAX Guide

     

    If this response resolved your issue, please mark it as correct to assist other members of the community.

  • Missing RETURN statement and it is needed when you use VAR (only). 

     

  • add after the last line: 

    RETURN

    result

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi awalker2009 

    Thank you for reaching out to the Microsoft Fabric Forum Community.

    @danextian sevenhills GeraldGEmerick Zanqueta  Thank you so much for your inputs.

    I hope the information provided by users was helpful. If you still have questions, please don't hesitate to reach out to the community.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi awalker2009 

      Hope everything’s going smoothly on your end. I wanted to check if the issue got sorted. if you have any other issues please reach community.