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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DAX Help

I would like to create DAX which pulls last 12 Months data based on selected date.

 

Example:

If user selects the current date June 10th ,2021 ,it should display last 12 months of data along with 10 Days of the June 2021 Month as well.

 

Basically ,The data should show in the dashboard  from June 1st 2020 to till date. When Apply the relative Date (is the last 12 months filter) option in the powerBI ,it showing from June 11th 2020 till date.

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @Anonymous,

I'd like to suggest you create a measure filter with custom expressions to filter records and use it on the visual level filter.

Applying a measure filter in Power BI - SQLBI

Measure =
VAR selected =
    MAX ( NewTable[Date] )
RETURN
    IF (
        MAX ( Table[Date] )
            IN CALENDAR (
                DATE ( YEAR ( selected ) - 1, MONTH ( selected ), DAY ( selected ) ),
                selected
            ),
        1,
        0
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

HI @Anonymous,

I'd like to suggest you create a measure filter with custom expressions to filter records and use it on the visual level filter.

Applying a measure filter in Power BI - SQLBI

Measure =
VAR selected =
    MAX ( NewTable[Date] )
RETURN
    IF (
        MAX ( Table[Date] )
            IN CALENDAR (
                DATE ( YEAR ( selected ) - 1, MONTH ( selected ), DAY ( selected ) ),
                selected
            ),
        1,
        0
    )

Regards,

Xiaoxin Sheng

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

A cheap version would be "in the last 365 days"  if you can live with the leap year issues.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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