Forum Discussion

mhdilyas's avatar
mhdilyas
Frequent Visitor
3 years ago

Last 5 weeks

IM trying to get data for last 4 week and current week but receive below error

Last 5 Week Today =
var _min1 = today() -WEEKDAY(today() ,1) -7 //Sunday week start
var _max = _min1 +6

var _min = _min1 - 4*7
return CALCULATE(ID[CountCRQ], FILTER(ID,ID[Submit Date] >=_min && ID[Submit Date] <= _max))

 

2 Replies

  • The error message "A table of multiple values was supplied where a single value was expected" typically occurs when a DAX expression is expecting a single value, but it receives a table or multiple values instead.

    In your case, the error is likely caused by the fact that the `ID[CountCRQ]` column is returning a table or multiple values within the `CALCULATE` function. To resolve this, you can modify your DAX expression to ensure that a single value is returned.

    Here's an updated version of your measure:

    ```DAX
    Last 5 Week Today =
    VAR _min1 = TODAY() - WEEKDAY(TODAY(), 1) - 7 // Sunday week start
    VAR _max = _min1 + 6

    VAR _min = _min1 - 4 * 7
    RETURN
    CALCULATE(
    COUNT(ID[CountCRQ]),
    FILTER(
    ALL(ID),
    ID[Submit Date] >= _min && ID[Submit Date] <= _max
    )
    )
    ```

    In the above expression, I changed `ID[CountCRQ]` to `COUNT(ID[CountCRQ])` within the `CALCULATE` function. This ensures that a single value is returned, which represents the count of `ID[CountCRQ]` within the specified date range.

    Additionally, I used the `ALL` function to remove any existing filters on the `ID` table. This allows the calculation to consider all rows within the date range specified by `_min` and `_max`.

    Make sure to replace `ID[Submit Date]` with the actual column reference for the submission date in your table.

    I hope this helps! Let me know if you have any further questions.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi mhdilyas ,

     

    Sorry, I need more details.

    What's your data? Is your formula a measure or a calculated column?

    What's the [CountCRQ]? Is [CountCRQ] a column or a measure?

    If possible, please provide me with some dummy data and expected result as tabular forms.

     

                                                                                                                                                             

    Best Regards,

    Stephen Tao

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.