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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
HDD328
Frequent Visitor

calculated column to find difference in value per day

Hello,

I am having trouble creating a calculated column that will take the Hrs value from the current day and subtract from the previous day for all incoming data. (example data below)

HDD328_0-1733835211199.png

 

I've tried multiple different ways, but can't seem to get the expected result. Any help is appreciated!

1 ACCEPTED SOLUTION
lkalawski
Resident Rockstar
Resident Rockstar

Hi @HDD328 ,

 

I suggest doing this type of calculation using a measure, because it is more optimal.

I have assumed Sum Hrs as Current Date, but this can be modified depending on the context of the task:

Cur Day Hours = 
Sum('Table'[Hrs])

 

Just calculate the Hrs value for the previous day:

Prv Day Hours = 
VAR __Date = MAX('Table'[DATE])
VAR __Unit = SELECTEDVALUE('Table'[Unit])
VAR __PrevDay = __Date - 1
VAR PreviousHrs = 
    CALCULATE(
        MAX('Table'[Hrs]),
        FILTER(
            ALL('Table'),
            'Table'[Unit] = SELECTEDVALUE('Table'[Unit]) &&
            'Table'[DATE] = MAX('Table'[DATE]) - 1
        )
    )
RETURN PreviousHrs

and then calculate the difference between today and yesterday:

Diff = 
VAR __Result = [Cur Day Hours] - [Prv Day Hours]

RETURN IF(ISBLANK([Prv Day Hours]), BLANK(), __Result)

 

The result:

lkalawski_0-1733838632794.png

PBI_SuperUser_Rank@1x.pngResident Rockstar | Former Super User
If I helped, please accept the solution and give kudos! 
Connect with me
Linkedin

 

View solution in original post

2 REPLIES 2
BITomS
Responsive Resident
Responsive Resident

Hi @HDD328 ,

 

I agree with @lkalawski that where possible, try to use measures. But for reference, this is how you could create a calculated column:

 

CalCol =
'Table'[Hrs]
- CALCULATE (
SUM ( 'Table'[Hrs] ),
ALL ( 'Table' ),
'Table'[UNIT] = EARLIER ( 'Table'[UNIT] ),
'Table'[DATE]
= EARLIER ( 'Table'[DATE].[Date] ) - 1
)

 

Hope this helps!

lkalawski
Resident Rockstar
Resident Rockstar

Hi @HDD328 ,

 

I suggest doing this type of calculation using a measure, because it is more optimal.

I have assumed Sum Hrs as Current Date, but this can be modified depending on the context of the task:

Cur Day Hours = 
Sum('Table'[Hrs])

 

Just calculate the Hrs value for the previous day:

Prv Day Hours = 
VAR __Date = MAX('Table'[DATE])
VAR __Unit = SELECTEDVALUE('Table'[Unit])
VAR __PrevDay = __Date - 1
VAR PreviousHrs = 
    CALCULATE(
        MAX('Table'[Hrs]),
        FILTER(
            ALL('Table'),
            'Table'[Unit] = SELECTEDVALUE('Table'[Unit]) &&
            'Table'[DATE] = MAX('Table'[DATE]) - 1
        )
    )
RETURN PreviousHrs

and then calculate the difference between today and yesterday:

Diff = 
VAR __Result = [Cur Day Hours] - [Prv Day Hours]

RETURN IF(ISBLANK([Prv Day Hours]), BLANK(), __Result)

 

The result:

lkalawski_0-1733838632794.png

PBI_SuperUser_Rank@1x.pngResident Rockstar | Former Super User
If I helped, please accept the solution and give kudos! 
Connect with me
Linkedin

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.