Forum Discussion

maliashwini04's avatar
maliashwini04
Frequent Visitor
2 years ago

The start date or end date in Calendar function can not be Blank value.

Hello ,I'm  New for power Bi and dax function 
I want to create MTD YTD Slicer Based on date Column .
I try to create slicer using following DAX Function 

MTD_YTD_Selection =
VAR TODAYDATE = TODAY()
VAR YearStart = CALCULATE(STARTOFYEAR(SalesTimeline[Date]), YEAR(SalesTimeline[Date]) = YEAR(TODAYDATE))
VAR MonthStart = CALCULATE(STARTOFMONTH(SalesTimeline[Date]), YEAR(SalesTimeline[Date]) = YEAR(TODAYDATE), MONTH(SalesTimeline[Date]) = MONTH(TODAYDATE))

VAR Result =
    UNION(
        ADDCOLUMNS(CALENDAR(YearStart, TODAYDATE), "Selection", "YTD"),
        ADDCOLUMNS(CALENDAR(MonthStart, TODAYDATE), "Selection", "MTD")
    )
RETURN
Result
But getting an error :
The start date or end date in Calendar function can not be Blank value.

Kindly help me to resolved error .

9 Replies

  • maliashwini04 

    have you try to use MIN instead of startofyear?

     

    What's more, you can try to return yearstart and monthstart to see if the output is blank or not

    • maliashwini04's avatar
      maliashwini04
      Frequent Visitor

      ryan_mayu Thank you ,
      Even after trying the MIN function, the error persists. The Date column contains date values and is not blank.
      Date column is in Sale Time table And sales value is in electric car table ,
      is there need to relation between them?
      in both table car sold is common column 

      • ryan_mayu's avatar
        ryan_mayu
        Super User

        maybe you can try this

         

        VAR YearStart = CALCULATE(STARTOFYEAR(SalesTimeline[Date]), filter(SalesTimeline,YEAR(SalesTimeline[Date]) = YEAR(TODAYDATE) && not (isblank(SalesTimeline[Date]))

         

        I didn't see you usesales value in the DAX.

         

        What did you get if you return YearStart  or return MonthStart?

         

        if the issue is still existing, could you pls share the pbix file?

  • maliashwini04's avatar
    maliashwini04
    Frequent Visitor

    I want to Create field parameter for MTD ,YTD ,QTD of car sales.
    Kindly Giude And Help me for the Same .