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
RogerSteinberg
Post Patron
Post Patron

Getting values from a relative period of the current row not working with datetime

Hi,

 

I have this following table: 

PeriodStartEndRevenueRevenue_1_week_agoMin_Date_1_week_agoMax_Date_1_week_ago
A1/17/2021 14:001/24/2021 14:00$1,000 1/10/2021 14:001/17/2021 14:00
B2/11/2021 14:002/17/2021 4:59$2,000 2/4/2021 14:002/10/2021 4:00

 

My formula for Min_Date_1_week_ago is :

Note that my transaction_date column is in datetime format

VAR min_date = min(AllPackages[transaction_date])
RETURN
min_date - (168/24)
 
As you can see it works fine because i want the same period from the week prior
 
My revenue formula is 
CALCULATE(
SUM(AllPackages[revenue]),
FILTER(
AllPackages,
AllPackages[transaction_date] >= [Min_Date_1_week_ago] && AllPackages[transaction_date]<=[Max_Date_1_week_ago]
)
)
 
I've tried adding the ALL inside the Filter function but doesnt work.
Im not sure why my revenue shows as blank
4 REPLIES 4
v-yangliu-msft
Community Support
Community Support

Hi  @RogerSteinberg  ,

I put your data into it and found these two problems

1. The data used in Sum cannot be of String type, you can check whether the type in [Revenue] is Text, if it is to be modified

2. Adjust your date types to be consistent, otherwise there will be no data

v-yangliu-msft_0-1617778621776.png

 

v-yangliu-msft_1-1617778621778.png

After I changed the date types to be consistent, the data is:

v-yangliu-msft_2-1617778621781.png

The result is:

v-yangliu-msft_3-1617778621783.png

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

THe max and min dates columns should not be columns but variables within measures. Since my report is really big, I would rather not have additional data points.

AllisonKennedy
Super User
Super User

@RogerSteinberg Are you doing these as calculated columns or measures? You need to consider the context the DAX calculates within. I can't tell what you're doing because your sample table has no Transaction_date column. Please share sample data set. 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

uhm really clueless how this report relates to my question.

my transaction_date column is in my model. its in a timestamp format. every sales figure are recorded on an hourly basis...

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.