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
Ronald123
Resolver III
Resolver III

Sum previous row by multiple checks

Hello,

 

I have the follow challange. I need a calculated colum with the follow calculation rules.

 

If the [DATE] && [CARD] is the same like the previous row and the time range of the colum [TIME] is
max.  5 minutes later than de previous time && [TYPE]=REFUND then i need on the max date row the sum of the colum [ AMOUNT].

 

I hope someone can help me.

Ronald 

 

Naamloos.png

1 ACCEPTED SOLUTION
Phil_Seamark
Employee
Employee

Hi @Ronald123

 

Here is a crack at a calculated column.  I have attached a PBIX file with my working.

 

 

Column = 
VAR LastValue = 
    SUMX(
        FILTER(
            'Table1',
            'Table1'[DATE] = EARLIER('Table1'[DATE]) &&
            'Table1'[CARD] = EARLIER('Table1'[CARD]) && 
            'Table1'[TIME] <= EARLIER('Table1'[TIME]) && 

            'Table1'[TIME] >= EARLIER('Table1'[TIME]) - "00:05:00"
            ),
       'Table1'[Amount])
VAR NextValue =        
           SUMX(
        FILTER(
            'Table1',
            'Table1'[DATE] = EARLIER('Table1'[DATE]) &&
            'Table1'[CARD] = EARLIER('Table1'[CARD]) && 
            'Table1'[TIME] > EARLIER('Table1'[TIME]) && 
             'Table1'[Type] = EARLIER('Table1'[Type]) &&
            'Table1'[Type] = "Refund" &&
            'Table1'[TIME] <= EARLIER('Table1'[TIME]) + "00:05:00"
            ),
       'Table1'[Amount])
RETURN 
    IF(
        NextValue>0,
        blank(),
        LastValue)
    
    

 

image.png

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

2 REPLIES 2
Phil_Seamark
Employee
Employee

Hi @Ronald123

 

Here is a crack at a calculated column.  I have attached a PBIX file with my working.

 

 

Column = 
VAR LastValue = 
    SUMX(
        FILTER(
            'Table1',
            'Table1'[DATE] = EARLIER('Table1'[DATE]) &&
            'Table1'[CARD] = EARLIER('Table1'[CARD]) && 
            'Table1'[TIME] <= EARLIER('Table1'[TIME]) && 

            'Table1'[TIME] >= EARLIER('Table1'[TIME]) - "00:05:00"
            ),
       'Table1'[Amount])
VAR NextValue =        
           SUMX(
        FILTER(
            'Table1',
            'Table1'[DATE] = EARLIER('Table1'[DATE]) &&
            'Table1'[CARD] = EARLIER('Table1'[CARD]) && 
            'Table1'[TIME] > EARLIER('Table1'[TIME]) && 
             'Table1'[Type] = EARLIER('Table1'[Type]) &&
            'Table1'[Type] = "Refund" &&
            'Table1'[TIME] <= EARLIER('Table1'[TIME]) + "00:05:00"
            ),
       'Table1'[Amount])
RETURN 
    IF(
        NextValue>0,
        blank(),
        LastValue)
    
    

 

image.png

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

@Phil_Seamark, Thanks, it works fine. Smiley Happy

 

 

 

 

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.