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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
noliverte
Helper III
Helper III

Total previous period dynamically

Hello,

 

I have the following measure :

Total Session LY all day = CALCULATE([Total Sessions-all];DATESBETWEEN(Calendrier[Calendar_Date];date(2019;01;01);date(2019;03;08)))))

 

--> It works fine but in a static way...

I'd like to replace date(2019;01;01) by the first day of the previous year

and date(2019;03;08) by today's date...

 

I also tried 

Total Sessions LY-all = CALCULATE([Total Sessions-all];SAMEPERIODLASTYEAR(Calendrier[Calendar_Date]))

But Total Session LY-all include until the end of march and not the today's date...

 

Any help is appreciated.

 

Thanks

 

1 ACCEPTED SOLUTION

Thanks a lot it works fine, I jest adapt your code to fit to my problem.

 

Total Session LY all day = CALCULATE([Total Sessions-all];
DATESBETWEEN(Calendrier[Calendar_Date];
DATE(YEAR(TODAY())-1;1;1);
DATE(YEAR(TODAY())-1;MONTH(TODAY());DAY(TODAY()-1))
)
)
 
Have a nice day
 
Noliverte

 

View solution in original post

4 REPLIES 4
v-alq-msft
Community Support
Community Support

Hi, @noliverte 

 

Based on your description, I created data to reproduce your scenario.

Table:

d1.png

 

Calendar(a calculated table):

 

Calendar = CALENDARAUTO()

 

 

Then you may create a measure as follows.

 

Total Session LY all day = 
CALCULATE(
    SUM('Table'[Sessions]),
    DATESBETWEEN(
        'Calendar'[Date],
        DATE(YEAR(TODAY())-1,1,1),
        TODAY()
    )
)

 

 

Today is 3/10/2020. So the measure doesn't include sessions for 3/11/2020 and 3/31/2020. Here is the result:

d2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Thanks a lot it works fine, I jest adapt your code to fit to my problem.

 

Total Session LY all day = CALCULATE([Total Sessions-all];
DATESBETWEEN(Calendrier[Calendar_Date];
DATE(YEAR(TODAY())-1;1;1);
DATE(YEAR(TODAY())-1;MONTH(TODAY());DAY(TODAY()-1))
)
)
 
Have a nice day
 
Noliverte

 

Greg_Deckler
Community Champion
Community Champion

See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

 



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

With time intelligence and date calendar you can try

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"))
This Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD((ENDOFYEAR('Date'[Date])),"12/31"))

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
Last YTD complete Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

 

In case you do not want to use date slicer

-- Force today filter
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"),'Date'[Date]<=today())

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"),'Date'[Date]<=date(year(today()-1),month(today()),day(today())))

-- with filter

YTD Sales 1= CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"))

Last YTD Sales 1 = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))

--combine

final YTD = if(isfiltered(Date[Month Year]) || isfiltered(Date[Year]) || isfiltered(Date[Date]),[YTD Sales 1],[YTD Sales])
final LYTD = if(isfiltered(Date[Month Year]) || isfiltered(Date[Year]) || isfiltered(Date[Date]),[Last YTD Sales 1],[Last YTD Sales])

 

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/

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors