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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Stabben23
Helper I
Helper I

Date Variable wrong format

Hi,

 

I want to create a variable in my DAX formula.

Var = maxdate= max(DateTable[Date])-7, this should gives me the maxdate from selected slicer in YYYY-MM-DD format but it gives me a numeric value for the date. So when I try to filter DateTable <= maxdate it doesent filter.

If I define the Variable like Date(2021-09-01) everything works fine.

3 REPLIES 3
Stabben23
Helper I
Helper I

I think I have to pologize, I work in Power Pivot, normally Power BI. And I now realize that these measure doesent act the same. All answers is probably correct. But in Power Pivot it fails when I put -7 in the formula.

If I skip -7 it shows me a results, but I can not find a way to offset my enddate.

Samarth_18
Community Champion
Community Champion

HI @Stabben23 ,

 

You can try below code:-

Measure =
VAR selected_date =
    SELECTEDVALUE ( table[date] )
VAR maxx_date =
    DATEVALUE ( FORMAT ( selected_date - 7, "YYYY-MM-DD" ) )
RETURN
    maxx_date

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Greg_Deckler
Community Champion
Community Champion

@Stabben23 That's odd. I can't replicate that behavior with a date table with a Date column.

Greg_Deckler_0-1631109239849.png

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.