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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
MjoGehri
Frequent Visitor

Calculate count by category and date- deduct if same date (condition)

Hello guys, im super new on this and i tried to find the solution online without success.

The situation is the following: 

We have many items produced by date, on the example below i have the pallet count and i need it to be deducted from previous if the date is the same:

 

MjoGehri_1-1653496145058.png

So basically, if is the same date, the following row should deduct from previous on pallet count.

 

Is there anyway to accomplish this?

 

Thank you

 

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@MjoGehri 

You need to add an index column to your table in Power Query first then add the following column using DAX:

New Count = 
VAR __CURRINDEX = 'Table6'[Index] 
VAR __CURRDATE = 'Table6'[Date]
VAR __PREVDATE = MAXX( FILTER( 'Table6', Table6[Index] = __CURRINDEX - 1) , 'Table6'[Date] )      
VAR __CURRAMT = 'Table6'[Count]
VAR __PREVAMT =  MAXX( FILTER( 'Table6', Table6[Index] = __CURRINDEX - 1) , 'Table6'[Count] )    
RETURN
    SWITCH(
        TRUE(),
        __CURRDATE = __PREVDATE , __CURRAMT - __PREVAMT,
        __CURRAMT
    )

Fowmy_0-1653510725352.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

1 REPLY 1
Fowmy
Super User
Super User

@MjoGehri 

You need to add an index column to your table in Power Query first then add the following column using DAX:

New Count = 
VAR __CURRINDEX = 'Table6'[Index] 
VAR __CURRDATE = 'Table6'[Date]
VAR __PREVDATE = MAXX( FILTER( 'Table6', Table6[Index] = __CURRINDEX - 1) , 'Table6'[Date] )      
VAR __CURRAMT = 'Table6'[Count]
VAR __PREVAMT =  MAXX( FILTER( 'Table6', Table6[Index] = __CURRINDEX - 1) , 'Table6'[Count] )    
RETURN
    SWITCH(
        TRUE(),
        __CURRDATE = __PREVDATE , __CURRAMT - __PREVAMT,
        __CURRAMT
    )

Fowmy_0-1653510725352.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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.