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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.