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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
ewkcoder
Frequent Visitor

Custom Table - Slicer For Date Periods - Calendar function can not be Blank value

I have a custom table that builds date slicer options for four periods (Year to date, Quarter to date, Month to date, Last 30 days).  The DAX below has been running fine but today it failed.  The month to date is the one causing it to fail.  Today is the first day of the month and I have no data yet and am getting the following error "The start date or end date in Calendar function can not be Blank value.".

 

I would like to prevent this error by checking if no records exist then hide the Month to date slicer option.  How would I do this with the DAX below?

 

 

calendar_mtd_qtd_ytd =
VAR TodayDate = TODAY()
VAR YearStart = CALCULATE(STARTOFYEAR(xxx[Created Date]), YEAR(xxx[Created Date]) = YEAR(TodayDate))
VAR QuarterStart = CALCULATE(STARTOFQUARTER(xxx[Created Date]), YEAR(xxx[Created Date]) = YEAR(TodayDate), QUARTER(xxx[Created Date]) = QUARTER(TodayDate))
VAR MonthStart = CALCULATE(STARTOFMONTH(xxx[Created Date]), YEAR(xxx[Created Date]) = YEAR(TodayDate), MONTH(xxx[Created Date]) = Month(TodayDate))
VAR Result =
UNION (
ADDCOLUMNS (
CALENDAR(YearStart, TodayDate),
"Selection", "YTD"
),
ADDCOLUMNS (
CALENDAR(QuarterStart, TodayDate),
"Selection", "QTD"
),
ADDCOLUMNS (
CALENDAR(MonthStart, TodayDate),
"Selection", "MTD"
),
ADDCOLUMNS (
CALENDAR(TODAY()-31, TodayDate-1),
"Selection", "Last 30 Days"
)
)
RETURN
Result

5 REPLIES 5
lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue.
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

ewkcoder
Frequent Visitor

Can you provide an example?

v-yiruan-msft
Community Support
Community Support

Hi  @ewkcoder ,

Whether your problem has been resolved? If yes, could you please mark the helpful post as Answered? It will help the others in the community find the solution easily if they face the same problem as yours. Thank you.

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-yiruan-msft
Community Support
Community Support

Hi @ewkcoder ,

Could you please show some sample data in the table xxxx[Created Date]? I just used the same formula with yours to create a calendar table, it works...

yingyinr_0-1662372659379.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
lbendlin
Super User
Super User

You need to branch out your VAR Result =   line into two different UNION statements. one with and one without the MTD choices.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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