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

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

Reply
Anonymous
Not applicable

If statement to sum values based on date on two tables

Hello I am trying to create a measure to sum values with an if statement across dates.. At present I have three tables (see below for more details) - The dax I am trying to write would sum the value of subscribers based on date, if the date selected is greater that the highest date in the subscriber date, then sum the subscribers in the customers table

 

Thanks in advance


Ideally, it would look like this

Date:                         customer number            subscribers (the measure I am trying to make)

March 2019.              1                                      10 (Historic Value from Subscribers table)
April 2019                 1                                       12 (Historic Value from Subscribers Table)
May 2019                  1                                       13 (Current Value from Customer Table)

 

To sum the number historical subscriptions. I am using the following dax:
historical subs =
CALCULATE(
          SUM(Subscribers[subscribersCount]), 
          USERELATIONSHIP(Subscribers[date],'Date'[Date])
)


To get the sum of current subscriptions. I am using the following dax:
Current Subs =
         Sum(customers[subscribers)

I have tried adding both of these as variables then using an if statment:

If (date[date] > subscribers[date], current subs,historical subs)

Table: Subscribers (has historical subscriber numbers)
Columns:

  • Date - Format (4/1/2019 all dates are at the first of the month)
  • CustomerID
  • Subscribers

Table: Customers (has current subscriber numbers)
Columns:

  • CustomerID
  • Customer Name
  • Subscribers (current number)

Table: Date (has current subscriber numbers)
Columns:

  • Date - Format: 8/1/2019
  • Months - Format: April 2019
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Found my own solution to the issue.. 

 

It was more simple than I was making it out to be. 

 

Subs (other) = 

var histsubs=
    CALCULATE(
        SUM(Subscribers[subscribersCount]),
        USERELATIONSHIP(Subscribers[date],'Date'[Date])
    )

var currsubs =
    CALCULATE(
        sum(Company[Active Subscribers]),
        'Date'[Date],
        USERELATIONSHIP(Company[OLM Company ID],Subscribers[customerId])
    )
var datecompare =
    IF(
        ISBLANK(histsubs),currsubs,histsubs
     )

RETURN
datecompare

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Using the following dax measure gets me really close..

 

Subscribers = 

var maxsubdate = ENDOFMONTH(Subscribers[date])
var seldate = STARTOFMONTH(ALLSELECTED('Date'[Date]))

var datecompare =
    IF(
        seldate > maxsubdate,0,1
     )

var histsubs=
    CALCULATE(
        SUM(Subscribers[subscribersCount]),
        USERELATIONSHIP(Subscribers[date],'Date'[Date])
    )

var currsubs =
    CALCULATE(
        sum(Company[Active Subscribers])
    )

var tbl=
            if(datecompare=1,
            CALCULATE(currsubs),
            CALCULATE(histsubs)
            )
RETURN
tbl


As you can see though from the screenshot below, it still does not populate the "current" value from customer table
Greenshot 2019-05-06 14.54.15.png

Anonymous
Not applicable

Found my own solution to the issue.. 

 

It was more simple than I was making it out to be. 

 

Subs (other) = 

var histsubs=
    CALCULATE(
        SUM(Subscribers[subscribersCount]),
        USERELATIONSHIP(Subscribers[date],'Date'[Date])
    )

var currsubs =
    CALCULATE(
        sum(Company[Active Subscribers]),
        'Date'[Date],
        USERELATIONSHIP(Company[OLM Company ID],Subscribers[customerId])
    )
var datecompare =
    IF(
        ISBLANK(histsubs),currsubs,histsubs
     )

RETURN
datecompare

Smiley Happy

 

Regards

Maggie

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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