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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Combining counta, sum, and datebetween functions in a column help

 

Hi I would like this formula for a column to count all provider names that have an application sum of 0 between 7/1/17-7/31/17.

If the sum is zero I would like to put a label that provider name saying "lapse" . Once I have this baseline, the goal is to create formulas on top of this to show whether they've lapsed for 1, 2, 3 months, etc.

How can I do this? 

 

CALCULATE ( counta ( LNApps_ProviderDim[Provider_Name] ), 'LNApps_Facts'[Total_Application_Amt] =0,DATESBETWEEN(LNApps_AppDateDim[ActualDate],  
    DATE(2017,7,1),  
    DATE(2017,7,30)))
1 ACCEPTED SOLUTION

@Anonymous

 

If you need to have your calculation group by ID and date, you can add ALLEXCEPT() into your CALCULATE().

 

=
CALCULATE (
    SUM ( LNApps_Facts[Application_Count] ),
    DATESBETWEEN (
        LNApps_AppDateDim[ActualDate],
        DATE ( 2017, 8, 1 ),
        DATE ( 2017, 8, 31 )
    ),
    ALLEXCEPT ( LNApps_Facts, LNApps_Facts[ID], LNApps_Facts[Date] )
)

Regards,

View solution in original post

7 REPLIES 7
Greg_Deckler
Super User
Super User

IF(CALCULATE ( counta ( LNApps_ProviderDim[Provider_Name] ), 'LNApps_Facts'[Total_Application_Amt] =0,DATESBETWEEN(LNApps_AppDateDim[ActualDate],  
    DATE(2017,7,1),  
    DATE(2017,7,30)))=0,"Lapse","Not Lapse")

?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks for your response. I receive this error: A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression. This is not allowed

 

 

Try doing your CALCULATE as a VAR and then your IF as a RETURN using your variable.

 

VAR m = CALCULATE(.....)

RETURN (IF(m=0...)

 

 

Something like that maybe.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks, I'll see if I can get that to work. I think I may need to try a different approach due to the way I want to build this out. 

 

CALCULATE(SUM(LNApps_Facts[Application_Count]), DATESBETWEEN(LNApps_AppDateDim[ActualDate], 
DATE(2017,8,1), 
DATE(2017,8,31) 
))

How can I use this formula but just sum by an ID?


If you create a Calendar Table(with Dates), and relate it to your "Fact Table" Date, you could ...

 

IF(

    ISBLANK(
          CALCULATE(
                DISTINCTCOUNT(LNApps_ProviderDim[Provider_Name]),
                FILTER(
                       ALL(Calendar),

                       Calendar[Date] <= MAX(Calendar[Date]) &&
                       Calendar[Date] >= MIN (Calendar[Date])

                       )
              )
        ),
      "Lapse",
      "Not Lapse"
)

Then you can use the same formula for every filter  

Anonymous
Not applicable

Thanks vcastello, I don't think I understand the formula, there's no summation in there. I want to avoid creating other tables because that tends to get hairy pretty fast for me. If I could just figure out how to sum the app count by ID and by date I think I will be okay. See below

.

CALCULATE(SUM(LNApps_Facts[Application_Count]), DATESBETWEEN(LNApps_AppDateDim[ActualDate], 
DATE(2017,8,1), 
DATE(2017,8,31) 
))

@Anonymous

 

If you need to have your calculation group by ID and date, you can add ALLEXCEPT() into your CALCULATE().

 

=
CALCULATE (
    SUM ( LNApps_Facts[Application_Count] ),
    DATESBETWEEN (
        LNApps_AppDateDim[ActualDate],
        DATE ( 2017, 8, 1 ),
        DATE ( 2017, 8, 31 )
    ),
    ALLEXCEPT ( LNApps_Facts, LNApps_Facts[ID], LNApps_Facts[Date] )
)

Regards,

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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