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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
DataNinja777
Super User
Super User

Getting the previous cost center information used for products in previous bookkeeping

Hello Power BI community,

 

I'd like to prepare bookeeping journal entry by taking the previous cost center used in the negative amount for particular products.  The required output is the 4th column, and negative entries are the clearing entries used previously for particular product, and I'd like to bring in the calculated column, the cost center used previously for the negative amount bookkeeping for the product.  I'd greatly appreciate it if anyone could write the dax formula for me to get the 4th column result from the 1-3 columns' information below. 

ProductAmountCost centerCost center output
A220US3UK1
B200US4UK3
C300US5UK5
D500US6UK8
E700US7UK9
F780US9UK9
E700US7UK9
A(220)UK1UK1
B(200)UK3UK3
C(300)UK5UK5
D(500)UK8UK8
E(700)UK9UK9
F(780)UK9UK9

Thanks a lot for your help!

1 ACCEPTED SOLUTION
danextian
Super User
Super User

hI @DataNinja777 ,

Assuming that you want to include in the logic the amount, try this:

 

Prev Cost Center = 
VAR __POSITIVE_AMOUNT =
    CALCULATE (
        MAX ( 'Table'[Cost center] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Product] = EARLIER ( 'Table'[Product] )
                && 'Table'[Amount] = - EARLIER ( 'Table'[Amount] )
        )
    )
VAR __NEGATIVE_AMOUNT =
    CALCULATE (
        MAX ( 'Table'[Cost center] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Product] = EARLIER ( 'Table'[Product] )
                && 'Table'[Amount] = EARLIER ( 'Table'[Amount] )
        )
    )
RETURN
    IF ( 'Table'[Amount] < 0, __NEGATIVE_AMOUNT, __POSITIVE_AMOUNT )

danextian_0-1700963156008.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

2 REPLIES 2
DataNinja777
Super User
Super User

Thank you!

danextian
Super User
Super User

hI @DataNinja777 ,

Assuming that you want to include in the logic the amount, try this:

 

Prev Cost Center = 
VAR __POSITIVE_AMOUNT =
    CALCULATE (
        MAX ( 'Table'[Cost center] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Product] = EARLIER ( 'Table'[Product] )
                && 'Table'[Amount] = - EARLIER ( 'Table'[Amount] )
        )
    )
VAR __NEGATIVE_AMOUNT =
    CALCULATE (
        MAX ( 'Table'[Cost center] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Product] = EARLIER ( 'Table'[Product] )
                && 'Table'[Amount] = EARLIER ( 'Table'[Amount] )
        )
    )
RETURN
    IF ( 'Table'[Amount] < 0, __NEGATIVE_AMOUNT, __POSITIVE_AMOUNT )

danextian_0-1700963156008.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.