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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
amalm
Helper III
Helper III

Calculating revenue based on activities in other rows

Hi, 

I have the following data:

 

Screenshot_20.png

 

I need to calculate revenues based on the following condition: 

An account is chargeable $1.9 if both activities (A1 & A2) have been performed. It is chargeable $0.6 if only A2 is performed (for some accounts A1 is not required). It is not chargeable anything if only A1 is performed (installation not completed).

 

A1 & A2 might be entered in the same row (if both are done by the same person in the same instance) or it may appear in different rows if it was done by different people or at different times. 

 

The result I expect is this:

Screenshot_19.png

 

Please let me know how this can be achieved. Thanks.

1 ACCEPTED SOLUTION
TeigeGao
Solution Sage
Solution Sage

Hi @amalm ,

We can use create the following calculated column directly:

Revenue =
VAR a =
    CALCULATE (
        CONCATENATEX ( Table1, Table1[Activity], " " ),
        FILTER ( ALL ( Table1 ), Table1[Account ID] = EARLIER ( Table1[Account ID] ) )
    )
RETURN
    IF (
        Table1[Activity] = "A1"
            && a = "A1 A2",
        0,
        IF (
            Table1[Activity] = "A2"
                && a = "A1 A2",
            1.9,
            IF (
                Table1[Activity] = "A1"
                    && a = "A1",
                0,
                IF ( Table1[Activity] = "A1 A2", 1.9, 0.6 )
            )
        )
    )

The result will like below:

Snipaste_2019-04-22_17-35-29.png

Best Regards,

Teige

View solution in original post

5 REPLIES 5
TeigeGao
Solution Sage
Solution Sage

Hi @amalm ,

We can use create the following calculated column directly:

Revenue =
VAR a =
    CALCULATE (
        CONCATENATEX ( Table1, Table1[Activity], " " ),
        FILTER ( ALL ( Table1 ), Table1[Account ID] = EARLIER ( Table1[Account ID] ) )
    )
RETURN
    IF (
        Table1[Activity] = "A1"
            && a = "A1 A2",
        0,
        IF (
            Table1[Activity] = "A2"
                && a = "A1 A2",
            1.9,
            IF (
                Table1[Activity] = "A1"
                    && a = "A1",
                0,
                IF ( Table1[Activity] = "A1 A2", 1.9, 0.6 )
            )
        )
    )

The result will like below:

Snipaste_2019-04-22_17-35-29.png

Best Regards,

Teige

Ashish_Mathur
Super User
Super User

Hi,

A1 and A2 are both performed for Account ID 1.  So Shouldn't the result for both rows be 1.9?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Did this in Power Query, so attached the pbix below. but:

  • Group the rows by ID and aggregate for All Rows
  • Create a new column that uses this group to build a list of activities:
List.Accumulate(
    [All Data][Activity],
    "",
    (state, current) => state & " "&current)
  • Expand the table, split the column in bullet #2 
  • Remove misc column so we just have ID, All Data and what the Prev activity was

Table after Accum and Split.png

 

add a custom column with:

if
[All Data.Activity] = "A2" and [Prev] ="A1"
then 1.9
else
if
[All Data.Activity] ="A2" and [Prev] <>"A1"
then
0.6
else
if
[All Data.Activity] ="A1" then 0
else
1.9

and final table:

Final Table.png

 

PBIX File:

https://1drv.ms/u/s!Amqd8ArUSwDS0nIhW0nl7uNLV3iQ

 

Hope that helps!

 

-Nick

@Anonymous Thank you, but you seem to have attached a different PBIX file.. Can you please attach the correct one so that I can check it out?

 

@Ashish_Mathur No, if both rows had $1.9 the totals would be wrong.

Anonymous
Not applicable

@amalm 

Sorry about that, this link should work better:

https://1drv.ms/u/s!Amqd8ArUSwDS0nT5n4LHAd3cmgc7

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.

Top Solution Authors