Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Hasvine2022
Helper I
Helper I

Calculate sales for last 30 days

Hello Team,

 

I am trying to calculate sales for the last 30 days using the below formula but it does not seem to be working:

 

TotalSales30Day =
CALCULATE (
SUM ( Sales_Main[Prix_Total_Vente_TTC] ),
DATESINPERIOD ( Calendar_1[Date], MAX ( Calendar_1[Date] ), -30, DAY )
)
 
Below is my calendar:
 
Calendar_1 = ADDCOLUMNS ( CALENDAR ( Date ( 2020 , 01 , 01 ),  date ( 2030 , 12 , 31 ))
, "Month Year" ,  Format ( [Date] ,  "MMM-YYYY" )
, "Month Year sort" ,  Format ( [Date] ,  "YYYYMM" )
, "Date_1" , FORMAT([Date], "DD/MM/YYYY")
, "Year" ,  Year ( [Date] )
, "YYYY-WK" , CONCATENATE( FORMAT ( [Date] , "YYYY" ),Format(WEEKNUM([Date],2)-1,"00"))
, "Qtr Year" ,  Format ( [Date] , "YYYY\QQ" ))
 
However, it does not seem to work:
 
Hasvine2022_0-1661925820909.png

 

 I need to show a table of sales for the last 30 days.
 
Could you please help?
 
Thank you.
 
Kind Regards,
 
Hasvine
 
3 REPLIES 3
v-jingzhang
Community Support
Community Support

Hi @Hasvine2022 

 

Please refer to this similar thread Solved: Calculate Sales Past 30 Days - Microsoft Power BI Community 

 

If possible, can you please show the relationship between Sales and Calendar tables? Inappropriate relationship may cause different results. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

PowerUserR
Solution Supplier
Solution Supplier

Hi,

I think this thread could help you: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Show-30-days-data-in-visual-before-the-date-s...

New Measure =
VAR __date_selected = MAX ( 'Calendar'[Date] ) // assuming there exists a calendar table in your model, and Calendar[Date] is sliced

VAR __period = DATESINPERIOD ( 'Calendar'[Date], __date_selected, -30, DAY )

VAR __inbetween =
    CALCULATE ( MAX ( factTable[Date] ), ALL ( 'Calendar'[Date] ) ) IN __period // slcier must be removed in order to keep all other dates in sight

RETURN
    IF ( __inbetween, [Old Measure] )

 

Hi,

 

Thank you for your help. It does not seem to work. 😞

 

New Measure =
VAR __date_selected = MAX ( Calendar_1[Date]  )

VAR __period = DATESINPERIOD ( Calendar_1[Date], __date_selected, -30, DAY )

VAR __inbetween =
    CALCULATE ( MAX ( Calendar_1[Date] ), ALL ( Calendar_1[Date] ) ) IN __period

RETURN
    IF ( __inbetween, Sum(Sales_Main[Prix_Total_Vente_TTC] ))
 
Is there something I am missing?
 
Thank you for your help.
 
Kind Regards,
 
Hasvine

 

 

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.