cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
New Member

Comparing values in the same column with different data field

I've this table that is incremented everyday with daily data. Now I would have a column in which I put the percentage difference between the values of "Positivi" column of the day with the values of one week earlier where possible(obviously for the first week it is impossible). How could I do this?

Thank you in advance

data.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Hi @EffePi,

It sounds like a general requirement to get the difference from current records with records before one week. I'd like to suggest you add a variable to get the last value before one week and compare it with the current one.

Measure =
VAR currDate =
    MAX ( Table[Date] )
VAR prevDate =
    CALCULATE (
        MAX ( Table[Date] ),
        FILTER ( ALLSELECTED ( Table ), [Amount] <> BLANK () && [Date] <= currDate - 7 ),
        VALUES ( Table[Category] )
    )
VAR prevAmount =
    CALCULATE (
        SUM ( Table[Amount] ),
        FILTER ( ALLSELECTED ( Table ), [Date] = prevDate ),
        VALUES ( Table[Category] )
    )
RETURN
    DIVIDE ( SUM ( Table[Amount] ) - prevAmount, prevAmount )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
Super User IV
Super User IV

@EffePi , if you want to do using measure, you can do with date table and measure like example

 

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]))
7 behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-7,DAy))

 

 

for week you need these columns in date table

Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)

 

measures
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)))


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 :radacad sqlbi My Video Series Appreciate your Kudos.



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Community Support
Community Support

Hi @EffePi,

It sounds like a general requirement to get the difference from current records with records before one week. I'd like to suggest you add a variable to get the last value before one week and compare it with the current one.

Measure =
VAR currDate =
    MAX ( Table[Date] )
VAR prevDate =
    CALCULATE (
        MAX ( Table[Date] ),
        FILTER ( ALLSELECTED ( Table ), [Amount] <> BLANK () && [Date] <= currDate - 7 ),
        VALUES ( Table[Category] )
    )
VAR prevAmount =
    CALCULATE (
        SUM ( Table[Amount] ),
        FILTER ( ALLSELECTED ( Table ), [Date] = prevDate ),
        VALUES ( Table[Category] )
    )
RETURN
    DIVIDE ( SUM ( Table[Amount] ) - prevAmount, prevAmount )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

Helpful resources

Announcements
November Update

Check it Out!

Click here to read more about the November 2020 Updates!

Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

secondImage

Power Platform October Community Highlights

Check out the top community contributors across all of the communities

secondImage

Create an end-to-end data and analytics solution

Learn how Power BI works with the latest Azure data and analytics innovations at the digital event with Microsoft CEO Satya Nadella.

Top Solution Authors
Top Kudoed Authors