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
CJMolin
Helper II
Helper II

Historical comparison on weekday - level basis

Hello,

 

I have a pretty big problem which I couldnt really solve by my own.

 

I have a huge dataset with several KPI's. I would like to be able to benchmark the historical result of these KPIs each weekday with the current result.

 

Example:

I would like to measure how many contracts I have sent out in average the last 3 weeks on a week day basis

Eg: 

Historical Mon week 1= 100

Historical Mon week 2= 200

Historical Mon week 3= 300

 

Historical Average past 3 weeks = 200

 

Current week Mon week 4 = 300, which means 50% increase compared to the previous 3 weeks average.

 

My dataset looks something like below. I'm first trying to get the acumulated sum of contracts sent out previous 14 days. But If i calculate the second columns it doesnt really exactly add up to the third columns aggregated total.

 

DAX measure used: 

test = CALCULATE([sales];FILTER(ALL(Dim_Calendar[Date]);Dim_Calendar[Date]<=MAX('Application'[DateDocsCustomer])&&Dim_Calendar[Date]>MAX('Application'[DateDocsCustomer])-14);USERELATIONSHIP(Dim_Calendar[Date];'Application'[DateDocsCustomer]))

 

2017-10-22673581
2017-10-21703717
2017-10-202553581
2017-10-193293581
2017-10-183603657
2017-10-174013581
2017-10-163603657
2017-10-15883729
2017-10-14983701
2017-10-133103581
2017-10-123553657
2017-10-113623657
2017-10-103903657
2017-10-094103581
2017-10-08953998
2017-10-07653605
2017-10-062683657
2017-10-054023657
2017-10-044233720
2017-10-034543657
2017-10-024213657
2017-10-01684094
2017-09-30793605
2017-09-293013657
2017-09-284123729
2017-09-273973701
2017-09-264123897
2017-09-253543581
2017-09-24674029
2017-09-23544094
2017-09-222693605
2017-09-213483960
2017-09-203604064
2017-09-193654012
2017-09-184393701

 

Please help me!

1 ACCEPTED SOLUTION

Hi @CJMolin,

 

From above example, which one is [Sales] column? Why do you need to calculate the acumulated sum of contracts in last 14 days?

 

I am not very clear about your requirement, please show us your ddesired result with examples. Based on my assumption, I created below formula to get the average value every 3 weeks.

WeekNum = WEEKNUM('Application'[DateDocsCustomer])
WeekDay = WEEKDAY('Application'[DateDocsCustomer],2) 

Average last three weeks =
CALCULATE (
    AVERAGE ( 'Application'[Sales] ),
    FILTER (
        'Application',
        'Application'[WeekNum] <= EARLIER ( 'Application'[WeekNum] )
            && 'Application'[WeekNum]
                > EARLIER ( 'Application'[WeekNum] ) - 3
            && 'Application'[WeekDay] = EARLIER ( 'Application'[WeekDay] )
    )
)

1.PNG

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

Haven't looked at this enough to present a full solution, but I would point you to the WEEKNUM and WEEKDAY functions in DAX.

 

https://msdn.microsoft.com/en-us/library/ee634572.aspx

 

https://msdn.microsoft.com/en-us/library/ee634550.aspx

 

You should be able to combine those with the TODAY function to achieve what you are looking for.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler,

 

Thanks. I am well aware of these functions. Although the problem I have is to get an average sum of [sales] the last x number of mondays,tuesdays etc etc.. As stated in the example in the description.

 

Hi @CJMolin,

 

From above example, which one is [Sales] column? Why do you need to calculate the acumulated sum of contracts in last 14 days?

 

I am not very clear about your requirement, please show us your ddesired result with examples. Based on my assumption, I created below formula to get the average value every 3 weeks.

WeekNum = WEEKNUM('Application'[DateDocsCustomer])
WeekDay = WEEKDAY('Application'[DateDocsCustomer],2) 

Average last three weeks =
CALCULATE (
    AVERAGE ( 'Application'[Sales] ),
    FILTER (
        'Application',
        'Application'[WeekNum] <= EARLIER ( 'Application'[WeekNum] )
            && 'Application'[WeekNum]
                > EARLIER ( 'Application'[WeekNum] ) - 3
            && 'Application'[WeekDay] = EARLIER ( 'Application'[WeekDay] )
    )
)

1.PNG

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 @v-yulgu-msft Hi!

 

That was exactly what I was looking for.. What I forgot in my forumla was weekday=earlier(weekday)!

 

Very much appreciated.

 

Btw, what tool are you using to convert your DAX to a more readable way? Like I always write my calculations just in one huge row which is very hard to read afterwords 🙂 

 

Thanks again!

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.