Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
maliashwini04
Frequent Visitor

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

Hello ,I'mScreenshot 2024-08-14 180452.png  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 9
maliashwini04
Frequent Visitor

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

pls see if this is what you want





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




ryan_mayu
Super User
Super User

@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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@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 

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?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@ryan_mayu 

 

Thank you for your response! I haven't included the Sale column in the DAX formula yet, and I'm a bit confused about where exactly to use it. Could you please provide the completed query with the Sale column added in the correct place?

I am also confused about how to put the sales column into your DAX. Let's go back from the beginning. Could you pls please provide the sample data and expected output? Then I can have a good understanding of your request. 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@ryan_mayu 

Calculate MTD ,YTD,QTD  like following 

MTD = CALCULATE(TOTALMTD([SumSales],DATESMTD(SalesTimeline[Date].[Date])))
QTD= CALCULATE(TOTALQTD([SumSales],DATESQTD(SalesTimeline[Date].[Date])))
YTD=
 CALCULATE(TOTALMTD([SumSales],DATESMTD(SalesTimeline[Date].[Date])))
And now want add above calculated measure in slicer(Date Time Inteligent Slicer)Dynamic Purpose 
when i select MTD option then visualization will change dispaly Month till date Sale in chart 
When i select QTD option the Visualization will change and display Quarter till date sales in chart 
when i select YTD Option then visualization will change and display Yera till date sale 

have you seen my attachment in my last reply?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.