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
driesvdb
Regular Visitor

Day to Day difference with 2 variables

Hello,

 

I made a db where our printerdata is sent to on a daily basis. 6 properties/OID's are scanned:

  • copy count black
  • copy count color
  • total copy
  • print count black
  • print count color
  • total print

I want to add an extra column wich calculates the difference from the last day but for the same printer and OID.

So far i got something like this:

 

Count(Daily) =
VAR PrintPreviousDay =
CALCULATE (
SUM ( COUNTER[Count] );
FILTER (
ALL ( COUNTER );
COUNTER[Date]
= EARLIER ( COUNTER[Date] )-1
&& COUNTER[PrinterID] = EARLIER ( COUNTER[PrinterID] )
&& COUNTER[TypecounterID] = EARLIER( COUNTER[TypecounterID] )
)
)
RETURN
COUNTER[Count] - PrintPreviousDay
 
But the new column only copies the count value instead of substracting it from the previous day.
PrinterID   TypecounterID    Date         Count      Count(Daily)
2019-10-08_14-23-57.png
 
Any help is appreciated to fix my formula.
 
Thanks
Dries
 
 
1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @driesvdb ,

 

To create a measure as below.

difference = 
VAR dat = [Date] - 1
VAR pre =
    CALCULATE (
        SUM ( 'Table'[Count] ),
        FILTER (
            'Table',
            'Table'[PrinterID] = EARLIER ( 'Table'[PrinterID] )
                && 'Table'[TypecounterID] = EARLIER ( 'Table'[TypecounterID] )
                && [Date] = dat
        )
    )
RETURN
    IF ( pre = BLANK (), BLANK (), 'Table'[Count] - pre )

Capture.PNG

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

2 REPLIES 2
v-frfei-msft
Community Support
Community Support

Hi @driesvdb ,

 

To create a measure as below.

difference = 
VAR dat = [Date] - 1
VAR pre =
    CALCULATE (
        SUM ( 'Table'[Count] ),
        FILTER (
            'Table',
            'Table'[PrinterID] = EARLIER ( 'Table'[PrinterID] )
                && 'Table'[TypecounterID] = EARLIER ( 'Table'[TypecounterID] )
                && [Date] = dat
        )
    )
RETURN
    IF ( pre = BLANK (), BLANK (), 'Table'[Count] - pre )

Capture.PNG

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Hi @v-frfei-msft 

 

When I enter the lines the collumn is still empty, no calculation seems te be done.

2019-10-09_14-03-53.png

In the link below is the .pbix file ( I don't have enough rights to upload it directly )

https://vgdeu-my.sharepoint.com/:u:/g/personal/dries_van_den_bossche_vgd_eu/ETYtyNXf-yJNrMl001ASATYB...

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.