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
Anonymous
Not applicable

Need help writing a measure for the last 2 weeks and then the previous 2 weeks before that

Hello I have a date column and also have a column of transactions per day and I need to write a measure to sum all of the transactions over the last two weeks and get the average per day and another to sum the transactions to get the average of the previous two weeks in the past. 

 

This is what I am getting and its not working

 

Avg Prev Daily Revenue Over 15-30 Days =
CALCULATE (
SUM ( fact_transaction[amount] ),
DATESINPERIOD( dim_date[date_actual], MAX ( dim_date[date_actual] ), -30, DAY ),
DATESINPERIOD( dim_date[date_actual], MIN( dim_date[date_actual] ), -15, DAY ))
1 ACCEPTED SOLUTION

Hi, @Anonymous 

Thank you for your feedback and explanation.

Please check the below measure and the link down below.

 

In the sample pbix file, you can refer to 1-measure and 5-measure.

 

5 Average of Running total for previous 15-30 days =
VAR runningtotal =
SUMX (
FILTER (
ALL ( Dates ),
Dates[Date]
> MAX ( Dates[Date] ) - 30
&& Dates[Date]
<= MAX ( Dates[Date] ) - 15
),
[1 Qty Total]
)
VAR howmanydaysintheperiod =
CALCULATE (
DISTINCTCOUNT ( Sales[Date] ),
FILTER (
ALL ( Dates ),
Dates[Date]
> MAX ( Dates[Date] ) - 30
&& Dates[Date]
<= MAX ( Dates[Date] ) - 15
)
)
VAR result =
DIVIDE ( runningtotal, howmanydaysintheperiod )
RETURN
result
 
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hello and thank you for the help. Unfortunately thats not what I am looking for. I need to get a daily running total of the previous 15 -30 days thats a;ways updates to the previous to 15 days. So taday is 4/26, the measure would look at the dates 3/27 to 4/11. Tomorrow on 4/27, the measure would look at the dates 3/28 to 4/12. I think I getting somewhere with the DAX but still need help. 

 

Avg Prev Daily Revenue Over 15 Days =
CALCULATE (
SUM ( fact_transaction[amount] ),
DATESINPERIOD( dim_date[date_actual], TODAY() -15, -30, DAY )
) / 15

Hi, @Anonymous 

Thank you for your feedback and explanation.

Please check the below measure and the link down below.

 

In the sample pbix file, you can refer to 1-measure and 5-measure.

 

5 Average of Running total for previous 15-30 days =
VAR runningtotal =
SUMX (
FILTER (
ALL ( Dates ),
Dates[Date]
> MAX ( Dates[Date] ) - 30
&& Dates[Date]
<= MAX ( Dates[Date] ) - 15
),
[1 Qty Total]
)
VAR howmanydaysintheperiod =
CALCULATE (
DISTINCTCOUNT ( Sales[Date] ),
FILTER (
ALL ( Dates ),
Dates[Date]
> MAX ( Dates[Date] ) - 30
&& Dates[Date]
<= MAX ( Dates[Date] ) - 15
)
)
VAR result =
DIVIDE ( runningtotal, howmanydaysintheperiod )
RETURN
result
 
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Jihwan_Kim
Super User
Super User

Hi, @Anonymous 

Please correct me if I wrongly understood your question.

Please check the below picture and the sample pbix file's link down below, whether it is what you are looking for.

 

All measures are in the sample pbix file, and all steps are numbered in front of each measure.

 

 

Picture4.png

 

https://www.dropbox.com/s/z04m7l77bs4np8i/gump.pbix?dl=0 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: https://www.linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


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.