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
Anonymous
Not applicable

Limited calendar with an IF statement

I have a dashboard that is navigable through a movable slicer set on Between that has a calendar in it. The formula I've set for it is:

 

Calendar = CALENDAR(DATE(2021,1,10),DATE(YEAR(TODAY()),MONTH(TODAY()),DAY(TODAY())))

 

 

Which is simple, my first data point happened in 2021/1/10, and the data source is updated daily with new info, hence why I put TODAY() functions in the end. This worked out perfectly for last year, but now that it's 2023 we changed our data source, and to avoid confusion while we still use that other dashboard as well as future-proof the new one, I wanted to base the calendar off an IF() function.

 

Calendar = IF(DATE(YEAR(TODAY()),MONTH(TODAY()),DAY(TODAY())) >= DATE(2022,12,31),
                CALENDAR(DATE(2021,1,10),DATE(2022,12,31)),
                CALENDAR(DATE(2021,1,10),DATE(YEAR(TODAY()),MONTH(TODAY()),DAY(TODAY())))
            )

 

 

This, however, broke my queries and returned the error: "The expression specified in the query is not a valid table expression". How would I be going on doing this correctly?

1 ACCEPTED SOLUTION

hi @Anonymous 

it seems the up limit of the calendar table shall be aligned with data record. 

try like:

Calendar = CALENDAR( DATE(2022, 1, 10), MAX(RecordTable[Date]))

try like:

View solution in original post

7 REPLIES 7
danextian
Super User
Super User

hi , 

I don't get why you're using DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), DAY ( TODAY () ) ) instead of simply TODAY ().

@Anonymous










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

Because I didn't know you could do that when I started this dashboard and left it as-is.

Padycosmos
Solution Sage
Solution Sage

Hope this helps

Padycosmos_6-1674607733855.png

 

FreemanZ
Super User
Super User

hi @Anonymous 

how about

Calendar = CALENDAR( DATE(2022, 1, 10), TODAY())

directly?

Anonymous
Not applicable

I mean, yes, I could do that. In fact it's what I'm using right now on my dashboard.

image_2023-01-25_004641890.png

 

 

What I want to do is to make it so when 2024 arrives, I don't have to make a patch that my boss has to download so they don't get confused about why 2024 is selectable when there's no data available. Today there was a bit of confusion surrounding 2023 in the 2022 dashboard, which is why I thought of using the IF() statement. If it's not possible, it's fine, I just want to be able to avoid that future change if I can.

hi @Anonymous 

it seems the up limit of the calendar table shall be aligned with data record. 

try like:

Calendar = CALENDAR( DATE(2022, 1, 10), MAX(RecordTable[Date]))

try like:

Anonymous
Not applicable

Nice trick! I didn't know you could do that. Thanks for the help!

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.