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
badluckmath
Frequent Visitor

Relative Value Between Dates

I want to get the relative value between dates in the table below:

 

Sem título.png

 

My goal is to create an cars showing  the relative values in the column "Quantidades".

Card 1 :  Today/ Yesterday

Card 2 : This week/ Last Week

Card 3: This month / Last Month

 

I'm new using Power  Bi, so any help is useful!

1 ACCEPTED SOLUTION
v-xuding-msft
Community Support
Community Support

Hi @badluckmath ,

 

Please try the following measures:

 

 

Today/ Yesterday =
VAR today_ =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER ( 'Table', 'Table'[Date] = TODAY () )
    )
VAR yesterday_ =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER ( 'Table', 'Table'[Date] = TODAY () - 1 )
    )
VAR NextMaxDate_ =
    MINX ( TOPN ( 2, ALL ( 'Table' ), 'Table'[Date], DESC ), 'Table'[Date] )
VAR NextDateQuan_ =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER ( 'Table', 'Table'[Date] = NextMaxDate_ )
    ) -- if there is no data yesterday, it calculates the value on next maximum date.
RETURN
    IF (
        ISBLANK ( yesterday_ ),
        DIVIDE ( today_, NextDateQuan_ ),
        DIVIDE ( today_, yesterday_ )
    )
This week/ Last Week =
VAR thisweek =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER ( 'Table', 'Table'[Week] = MAX ( 'Table'[Week] ) )
    )
VAR lastweek =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER ( 'Table', 'Table'[Week] = MAX ( 'Table'[Week] ) - 1 )
    )
RETURN
    DIVIDE ( thisweek, lastweek )
This Month/ Last Month =
VAR thismonth =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER ( 'Table', MONTH ( 'Table'[Date] ) = MONTH ( MAX ( 'Table'[Date] ) ) )
    )
VAR lastmonth =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER (
            'Table',
            MONTH ( 'Table'[Date] )
                = MONTH ( MAX ( 'Table'[Date] ) ) - 1
        )
    )
RETURN
    DIVIDE ( thismonth, lastmonth )

 

 

If you don't want to calculate percentage, please try this:

 

This week VS Last Week =
VAR thisweek =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER ( 'Table', 'Table'[Week] = MAX ( 'Table'[Week] ) )
    )
VAR lastweek =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER ( 'Table', 'Table'[Week] = MAX ( 'Table'[Week] ) - 1 )
    )
RETURN
    thisweek & " VS " & lastweek

 

 
Best Regards,
Xue Ding
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
v-xuding-msft
Community Support
Community Support

Hi @badluckmath ,

 

Please try the following measures:

 

 

Today/ Yesterday =
VAR today_ =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER ( 'Table', 'Table'[Date] = TODAY () )
    )
VAR yesterday_ =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER ( 'Table', 'Table'[Date] = TODAY () - 1 )
    )
VAR NextMaxDate_ =
    MINX ( TOPN ( 2, ALL ( 'Table' ), 'Table'[Date], DESC ), 'Table'[Date] )
VAR NextDateQuan_ =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER ( 'Table', 'Table'[Date] = NextMaxDate_ )
    ) -- if there is no data yesterday, it calculates the value on next maximum date.
RETURN
    IF (
        ISBLANK ( yesterday_ ),
        DIVIDE ( today_, NextDateQuan_ ),
        DIVIDE ( today_, yesterday_ )
    )
This week/ Last Week =
VAR thisweek =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER ( 'Table', 'Table'[Week] = MAX ( 'Table'[Week] ) )
    )
VAR lastweek =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER ( 'Table', 'Table'[Week] = MAX ( 'Table'[Week] ) - 1 )
    )
RETURN
    DIVIDE ( thisweek, lastweek )
This Month/ Last Month =
VAR thismonth =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER ( 'Table', MONTH ( 'Table'[Date] ) = MONTH ( MAX ( 'Table'[Date] ) ) )
    )
VAR lastmonth =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER (
            'Table',
            MONTH ( 'Table'[Date] )
                = MONTH ( MAX ( 'Table'[Date] ) ) - 1
        )
    )
RETURN
    DIVIDE ( thismonth, lastmonth )

 

 

If you don't want to calculate percentage, please try this:

 

This week VS Last Week =
VAR thisweek =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER ( 'Table', 'Table'[Week] = MAX ( 'Table'[Week] ) )
    )
VAR lastweek =
    CALCULATE (
        SUM ( 'Table'[Quantidade] ),
        FILTER ( 'Table', 'Table'[Week] = MAX ( 'Table'[Week] ) - 1 )
    )
RETURN
    thisweek & " VS " & lastweek

 

 
Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

@badluckmath , Try if this can help

 

Day behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Day))
This Day = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Date]=max('Date'[Date])))
Last Day = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Date]=max('Date'[Date])-1))
Last Day = CALCULATE(sum('order'[Qty]), previousday('Date'[Date]))

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))

 

Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
This Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))
Last year Week= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=(max('Date'[Week Rank]) -52)))

 

Power BI — MTD
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
Power BI — WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
Power BI — Day Intelligence
https://medium.com/@amitchandak.1978/power-bi-day-intelligence-questions-time-intelligence-5-5-5c324...

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
Greg_Deckler
Community Champion
Community Champion

@badluckmath - See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])
  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous

 

Otherwise, I agree with @lbendlin 



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...
lbendlin
Super User
Super User

please provide the sample data in usable format.

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