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
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
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.