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
EffePi
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
v-shex-msft
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
v-shex-msft
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.
amitchandak
Super User
Super User

@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.

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.