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
yugofukuda
Helper IV
Helper IV

12 month average on the same day

Hi,

 

For calculating a forecast, I would like to create the average of % on the same working day of last 12 months.

I would be appreciated if you could help me. Thanks!!

Sample99.png

1 ACCEPTED SOLUTION

Please try this one instead.  I didn't notice before that you have the Month column in the visual (not dates).

 

Collection % Last 12 Months =
VAR thisdate =
MAX ( 'Calendar'[Date] )
VAR last12months =
CALCULATETABLE (
VALUES ( 'Calendar'[Month] ),
ALL ( 'Calendar' ),
'Calendar'[Date] <= EOMONTH ( thisdate, 0 ),
'Calendar'[Date] >= EOMONTH ( thisdate, -11 )
)
RETURN
AVERAGEX ( last12months, [Collection %] )
 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

11 REPLIES 11
mahoneypat
Employee
Employee

Please try this expression

 

Avg Same WD =
VAR thisWD =
    MIN ( 'Date'[WD 22] )
VAR thisdate =
    MIN ( 'Date'[Date] )
RETURN
    AVERAGEX (
        FILTER (
            ALL ( 'Date'[Date] ),
            'Date'[Date] <= EOMONTH ( thisdate, 0 )
                && 'Date'[Date] >= EOMONTH ( thisdate, -12 )
                && 'Date'[WD 22] = thisWD
        ),
        [Percent Measure]
    )

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@mahoneypat 

Thank you for your quick response!!

I don´t know why but i can´t put "Calendar WD22" in the part below. How should I do??

 

Avg Same WD =
VAR thisWD =
MIN ('Calendar'[WD 22])
VAR thisdate =
MIN ( 'Calendar'[Date] )
RETURN
AVERAGEX (
FILTER (
ALL ( 'Calendar'[Date]),
'Calendar'[Date] <= EOMONTH ( thisdate, 0 )
&& 'Calendar'[Date] >= EOMONTH ( thisdate, -12 )
&& 'Date'[WD 22] = thisWD
),
'Daily Collection'[Collection %]
)
 

Sample2020.png

My bad.  Forgot about that column.  Try this version.

 

Avg Same WD =
VAR thisWD =
MIN ('Calendar'[WD 22])
VAR thisdate =
MIN ( 'Calendar'[Date] )
RETURN
AVERAGEX (
FILTER (
ALL ( 'Calendar'[Date], 'Calendar'[WD 22]),
'Calendar'[Date] <= EOMONTH ( thisdate, 0 )
&& 'Calendar'[Date] >= EOMONTH ( thisdate, -12 )
&& 'Date'[WD 22] = thisWD
),
'Daily Collection'[Collection %]
)
 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@mahoneypat 
Thank you very much but It seems to me that it don´t work well.  There are something that I should change??

 

Sample1111.png

 

Please share the Collection % measure.

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@mahoneypat 

Collection % = 'Daily Collection'[Collection for forecast]/calculate(sum(collection),all('Calendar'[WD 22]))
Collection for forecast = TOTALMTD(sum(collection),'Calendar'[Date])
 
Regards,

Signing off the the night.  Will take a look again tomorrow, if someone else doesn't solve it first.

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@mahoneypat  Thank you very much for your help!!

Please try this one instead.  I didn't notice before that you have the Month column in the visual (not dates).

 

Collection % Last 12 Months =
VAR thisdate =
MAX ( 'Calendar'[Date] )
VAR last12months =
CALCULATETABLE (
VALUES ( 'Calendar'[Month] ),
ALL ( 'Calendar' ),
'Calendar'[Date] <= EOMONTH ( thisdate, 0 ),
'Calendar'[Date] >= EOMONTH ( thisdate, -11 )
)
RETURN
AVERAGEX ( last12months, [Collection %] )
 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@mahoneypat 

Thank you very much!! It woked well!! you are so smart.

 

Sorry, could you do me a favor?? (other matter)

For calculating forecast, I created the expression as below but I don't know how to insert today´s WD22 automatically (for example, today´s wd22 is 17.  I tried to use calculate or lookupvalue but it didn´t work well.
Could you help me??
 

For Forecast =
CALCULATE('Daily Collection'[Collection % Last 12 Months],
'Calendar'[WD 22]=17  *I would like to put 17 automatically. 
,'Calendar'[Month]=format( DATE(YEAR(TODAY()),MONTH(TODAY())-1,DAY(TODAY())),"YYYY-MM"))


sample1010101.png

 

 

 

Greg_Deckler
Super User
Super User

@yugofukuda - You can create this column:

IsWorkingDay = IF(WEEKDAY([Date],2) < 6,1,0)

And then this column will return the working day number of every day in each month:

WorkingDay# = 
    VAR __WorkingDay = COUNTROWS(FILTER('Calendar',YEAR([Date])=YEAR(EARLIER([Date])) && MONTH([Date])=MONTH(EARLIER([Date])) && [Date]<=EARLIER([Date]) && [IsWorkingDay]=1))
RETURN
    IF([IsWorkingDay]=0,0,__WorkingDay)

PBIX is attached below sig.


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

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.