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
harirao
Post Prodigy
Post Prodigy

Creating Trend comparing current week with previous week

Hi Team,

Required assistance, I am trying to create weekly trend comparing current wk vs previous week, used below dax  but not getting correct result
Colum:

PreviousReportDate = DATEADD(Query1[reportdate],-7,DAY)

Measure, highlighted in red is also measure 
Trend =
CALCULATE([%6week_1&2], FILTER(ALL(Query1),Query1[reportdate]=SELECTEDVALUE(Query1[PreviousReportDate]) && Query1[subregion]=SELECTEDVALUE(Query1[subregion])))

Below is screen print where Trend suppose to get 18th data but getting incorrect result 
25th  Data25th Data

18th 
18th Data18th Data
Once i get correct result for Trend i can create new Measure as per below comparison.
3.PNG


Regards,
Hari
 




2 ACCEPTED SOLUTIONS
AllisonKennedy
Super User
Super User

@harirao  I'm assuming you have a DimDate table?? 

 

If not, get one, they make a big difference:

https://excelwithallison.blogspot.com/2020/04/dimdate-what-why-and-how.html

 

Once you have the date table, I would consider a slightly different approach to this problem, using time intelligence to change the filter context within the measure, rather than creating a calculated column for previous period. 

 

So something like: 

 

Trend =
CALCULATE([%6week_1&2], DATEADD(DimDate[Date], -7, DAY))
 
No need to mess with region as that will come automatically from the context of the matrix. 
 
@harirao  A small update:
In the slicer, either use the:
DimDate[Date] ,
DimDate[ReportWeek]
DimDate[Week]
 
Basically anything from the DimDate table NOT the Query1[reportdate]

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

View solution in original post

amitchandak
Super User
Super User

@harirao , refer to my blog on how to work with the week; this week vs last week etc.

https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...


Appreciate your Kudos.

 

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@harirao , refer to my blog on how to work with the week; this week vs last week etc.

https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...


Appreciate your Kudos.

 

AllisonKennedy
Super User
Super User

@harirao  I'm assuming you have a DimDate table?? 

 

If not, get one, they make a big difference:

https://excelwithallison.blogspot.com/2020/04/dimdate-what-why-and-how.html

 

Once you have the date table, I would consider a slightly different approach to this problem, using time intelligence to change the filter context within the measure, rather than creating a calculated column for previous period. 

 

So something like: 

 

Trend =
CALCULATE([%6week_1&2], DATEADD(DimDate[Date], -7, DAY))
 
No need to mess with region as that will come automatically from the context of the matrix. 
 
@harirao  A small update:
In the slicer, either use the:
DimDate[Date] ,
DimDate[ReportWeek]
DimDate[Week]
 
Basically anything from the DimDate table NOT the Query1[reportdate]

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

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.