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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
davidwhite83
Frequent Visitor

Joining Rows

I am trying to create a financial report from our companies financial data. I want to compute the total gross profit from our labor sales and labor cost. Once the GP is generated I want it deduct from the expenses to give me a net profit. 

 

Question1: How to combine Rows so that I get overall gross profit:

 

Labor TypeAcct#Acct TypeAmount
CP - CP Labor4400Sale

$25.00

CC - CP Labor COS6400COS

$12.00

WP - WP Labor4600Sale

$30.00

WC - WP Labor COS6600COS

$13.00

 

So I want to combine CP and WP so that the Total Sales amount is $55.00. Create a calculation to combine CP and CC to show gross as $13.00, and then combine CP Gross and WP Gross to show over gross profit of $30.00.

 

Any assistance will be good. 

1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @davidwhite83 ,

You can create a calculated column to define the category first:

 

Category = 
IF (
    CONTAINSSTRING ( 'Table'[Labor Type], "CP" ),
    "CP",
    IF ( CONTAINSSTRING ( 'Table'[Labor Type], "WP" ), "WP" )
)

 

Then create two measures to calculate the total and gross profit.

 

Total Sales = 
CALCULATE (
    SUM ( 'Table'[Amount] ),
    FILTER ( 'Table', 'Table'[Acct Type] = "Sale" )
)
Gross profit = 
VAR tab =
    SUMMARIZE (
        'Table',
        'Table'[Category],
        'Table'[Acct Type],
        'Table'[Amount],
        "A",
            CALCULATE (
                SUM ( 'Table'[Amount] ),
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Category] = EARLIER ( 'Table'[Category] )
                        && 'Table'[Acct Type] = "Sale"
                )
            )
                - CALCULATE (
                    SUM ( 'Table'[Amount] ),
                    FILTER (
                        ALL ( 'Table' ),
                        'Table'[Category] = EARLIER ( 'Table'[Category] )
                            && 'Table'[Acct Type] = "COS"
                    )
                )
    )
RETURN
    SUMX ( SUMMARIZE ( tab, [A] ), [A] )

 

sale.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yingjl
Community Support
Community Support

Hi @davidwhite83 ,

You can create a calculated column to define the category first:

 

Category = 
IF (
    CONTAINSSTRING ( 'Table'[Labor Type], "CP" ),
    "CP",
    IF ( CONTAINSSTRING ( 'Table'[Labor Type], "WP" ), "WP" )
)

 

Then create two measures to calculate the total and gross profit.

 

Total Sales = 
CALCULATE (
    SUM ( 'Table'[Amount] ),
    FILTER ( 'Table', 'Table'[Acct Type] = "Sale" )
)
Gross profit = 
VAR tab =
    SUMMARIZE (
        'Table',
        'Table'[Category],
        'Table'[Acct Type],
        'Table'[Amount],
        "A",
            CALCULATE (
                SUM ( 'Table'[Amount] ),
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Category] = EARLIER ( 'Table'[Category] )
                        && 'Table'[Acct Type] = "Sale"
                )
            )
                - CALCULATE (
                    SUM ( 'Table'[Amount] ),
                    FILTER (
                        ALL ( 'Table' ),
                        'Table'[Category] = EARLIER ( 'Table'[Category] )
                            && 'Table'[Acct Type] = "COS"
                    )
                )
    )
RETURN
    SUMX ( SUMMARIZE ( tab, [A] ), [A] )

 

sale.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

ToddChitt
Super User
Super User

This is the Power Query forum, but that won't stop us from giving DAX advice:

 

Create 2 new measures:

Total Sales = CALCULATE ( SUM ('Table Name'[Amount]), 'Table Name'[Type] = "Sales" )

Total COS = CALCULATE ( SUM ('Table Name'[Amount]), 'Table Name'[Type] = "COS" )

 

That should get you started. For more comples calculations, you will need the OR operator in the FILTER portion of the CALCULATE statement like this:

 

Total CC and CP = CALCULATE ( SUM ('Table Name'[Amount]), 'Table Name'[Labor Type] = "CP - CP Labor" ) ||  'Table Name'[Labor Type] = "CC - CP Labor COS" )

 

Hope that helps.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors