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