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

Filter table by previous date

Hello everyone!

I am new to DAX but I have a situation here that I thought I got right but apparently I didn't. I have two tables one Run Info and another Runtime Info. Both have Date columns but Run Info also has a Previous Date column which basically gets the previous row of Date like shown bellow:

Date             Previous Date
3/3/2020      
4/4/2020      3/3/2020

What I want to do is get the current Date from a matrix visualisation, get the Previous Date of that Date from Run Info, Filter Runtime Info by Previous Date and get the Average of a column called Event Time. I've created the measure bellow, but it doesn't seem to return any data to the visualization.

Previous Average Event Time =
CALCULATE(
        AVERAGE('Runtime Info'[Event Time]),
        FILTER('Runtime Info', RELATED('Run Info'[Previous Date]) = 'Runtime Info'[Date])
)

 
dax issue.png

 

What am I missing here? I was sure it would work for some reason. Thank you in advance!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous 

Use a Date calendar

If you have continuous dates

Day behind Sales = CALCULATE(AVERAGE('Runtime Info'[Event Time]),dateadd('Date'[Date],-1,Day))

 

If the last date is not -1 day, last date with Data

Last Day Non Continous = CALCULATE(AVERAGE('Runtime Info'[Event Time]),filter(all('Date'),'Date'[Date] =MAXX(FILTER(all('Date'),'Date'[Date]<max('Date'[Date])),'Date'[Date])))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

6 REPLIES 6
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

Try this

Previous Average Event Time = 
VAR __previusDate = SELECTEDVALUE( 'Run Info'[Previous Date] )
RETURN 
CALCULATE(
    AVERAGE( 'Runtime Info'[Event Time] ),
    ALL( 'Runtime Info' ),
    'Runtime Info'[Date] = __previusDate
)

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

How you could get the last record of the month until the selected date.

Example:

I have the following table:

Date Amount
05-01-2019 20
23-01-2019 15
15-02-2019 30
12-03-2019 10
24-03-2019 5
04-04-2019 15
13-04-201910
28-04-201912

and I select in a date filter the date 15-04-2019

Then I wish I could get the following table:

one-19 feb-19 mar-19 Apr-19
Amount 15 30 5 10

As I can do this, since I only manage to get the last data of the month or the last record of the month of the selected date but not both.

I hope you can help me, greetings and thank you in advance

Anonymous
Not applicable

Hi @Mariusz 

Thank you for your reply! I tried it and I got the following data. So something good is happening but it's not quite there yet. Any thoughts?

dax issue 2.png

amitchandak
Super User
Super User

@Anonymous 

Use a Date calendar

If you have continuous dates

Day behind Sales = CALCULATE(AVERAGE('Runtime Info'[Event Time]),dateadd('Date'[Date],-1,Day))

 

If the last date is not -1 day, last date with Data

Last Day Non Continous = CALCULATE(AVERAGE('Runtime Info'[Event Time]),filter(all('Date'),'Date'[Date] =MAXX(FILTER(all('Date'),'Date'[Date]<max('Date'[Date])),'Date'[Date])))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

Hi @amitchandak 

 

**bleep** the second one worked!!! Thank you so much!! If it isn't too much of a trouble, do you have any idea why the one I did, didn't work? The calculated column that created the previous date worked like this:

Previous Date = CALCULATE(
            MAX('Run Info'[Run Date]),
            FILTER('Run Info','Run Info'[Run Date]<EARLIER('Run Info'[Run Date]))
)

Thank you either way though. Your solution worked!

How you could get the last record of the month until the selected date.

Example:

I have the following table:

DateAmount
05-01-201920
23-01-201915
15-02-201930
12-03-201910
24-03-20195
04-04-201915
13-04-201910
28-04-201912

and I select in a date filter the date 15-04-2019

Then I wish I could get the following table:

one-19feb-19mar-19Apr-19
Amount1530510

As I can do this, since I only manage to get the last data of the month or the last record of the month of the selected date but not both.

I hope you can help me, greetings and thank you in advance

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.