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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Croshay
Frequent Visitor

SUM based on VAR value/ Subscription Revenue Total

I want to get a total revenue measure but am having issues. I have three tables Customers and Product and Date.
Relevent Fields for Customer:

CompanyStart DateProduct ID
A1/1/202010
B1/1/202111


Product:

PriceID
25010
11011


I have a DAX expression currently that finds the price and how many months of activity and gets me revenue based per company and per product, but not a total revenue. 

I want to be able to get all revenue across all companies and products and then filter with my charts later.

Here is the expression I currently have. 

Revenue =
    VAR company = SELECTEDVALUE(Customers[Company])
    VAR productID = SELECTEDVALUE(Customers[Product ID])
    Var firstPayment = 1
    Var startdate = SELECTEDVALUE(Customers[Start Date])
    Var endDate = MAX(__Dates[Date])
    VAR productPrice = CALCULATE(
        VALUES(
            'Product'[Price]
        ),
        'Product'[ID] = productID
    )
    VAR dateDifference = DATEDIFF(SELECTEDVALUE(Customers[Subscription Date]),
                endDate,
                MONTH
            )
    VAR paymentMonths = IF(dateDifference >= 0, dateDifference+firstPayment, 0)
    Return SUMX(Customers, paymentMonths*productPrice)

How can I get a regular SUM() to work with it. I know some people got CALCULATETABLE(SUMMERIZE()) to do this, but when I tried that I kept getting error messages. 

1 ACCEPTED SOLUTION
cengizhanarslan
Super User
Super User

Please try the measure below:

Revenue =
SUMX (
    Customers,
    VAR _startDate    = Customers[Start Date]
    VAR _endDate      = MAX ( __Dates[Date] )
    VAR _productPrice =
        CALCULATE (
            MAX ( 'Product'[Price] ),
            'Product'[ID] = Customers[Product ID]
        )
    VAR _dateDifference =
        DATEDIFF ( _startDate, _endDate, MONTH )
    VAR _paymentMonths =
        IF ( _dateDifference >= 0, _dateDifference + 1, 0 )
    RETURN
        _paymentMonths * _productPrice
)
_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn | Follow on Medium
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.

View solution in original post

3 REPLIES 3
cengizhanarslan
Super User
Super User

Please try the measure below:

Revenue =
SUMX (
    Customers,
    VAR _startDate    = Customers[Start Date]
    VAR _endDate      = MAX ( __Dates[Date] )
    VAR _productPrice =
        CALCULATE (
            MAX ( 'Product'[Price] ),
            'Product'[ID] = Customers[Product ID]
        )
    VAR _dateDifference =
        DATEDIFF ( _startDate, _endDate, MONTH )
    VAR _paymentMonths =
        IF ( _dateDifference >= 0, _dateDifference + 1, 0 )
    RETURN
        _paymentMonths * _productPrice
)
_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn | Follow on Medium
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.

It worked! Thank you so much @cengizhanarslan. This feels like magic! If you have a moment to explain why this worked I'd love that, but you've done so much so I get it if you don't.

I did have to add a line above _product price that was:

 VAR productID = Customers[Product ID]

But after it worked beautifully!

 

I'm glad it worrked! Basically you need to give variables inside the SUMX iteration because otherwise it does now obey the row context within the visual.

_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn | Follow on Medium
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.