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

Calculate the sum of some values with a conditional date

Hi, I have a table like this:

 

Client NameContract startContract endAuthorized Users
Customer B30/06/202027/12/20205
Customer B15/06/202129/06/202210
Customer A01/10/202130/12/202110
Customer B30/11/202129/11/202210
Customer A02/01/202201/01/202310
Customer B01/05/202230/04/202340

 

And a date reference table(calendar), I would like to know, for a certain period of time in the slicer, what is the number of authorized users, and being able to slice it also by client name, I have done this formula but it doesn't work properly.

 

Total Contracted Users =
VAR CurrentDate = MAX('calendar'[Date])
VAR ContractedUsers =
CALCULATE(
SUM('Contracts Master Table'[Authorized Users]),
ALL('calendar'),
'calendar'[Date]<=CurrentDate,
ISBLANK('Contracts Master Table'[Contract end])
|| 'Contracts Master Table'[Contract end]>=CurrentDate
)
RETURN
ContractedUsers
 
Any help is welcome!
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thank you @speedramps it worked, just I had to use MAX instead of SELECTEDVALUE for the first variable because it was not working. My final formula is 

 

 

No. Contracted Users = 
VAR CurrentDate = MAX('calendar'[Date])
VAR ContractedUsers =
FILTER('Contracts Master Table',
'Contracts Master Table'[Contract start]<= CurrentDate &&
'Contracts Master Table'[Contract end] >= CurrentDate)
RETURN
CALCULATE(
    SUM('Contracts Master Table'[Authorized Users]),
    ContractedUsers
) 

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thank you @speedramps it worked, just I had to use MAX instead of SELECTEDVALUE for the first variable because it was not working. My final formula is 

 

 

No. Contracted Users = 
VAR CurrentDate = MAX('calendar'[Date])
VAR ContractedUsers =
FILTER('Contracts Master Table',
'Contracts Master Table'[Contract start]<= CurrentDate &&
'Contracts Master Table'[Contract end] >= CurrentDate)
RETURN
CALCULATE(
    SUM('Contracts Master Table'[Authorized Users]),
    ContractedUsers
) 

 

speedramps
Super User
Super User

Try this solution with your correct table / field names.

I have added comments so yoy can learm dax ....

 

Create a detached calendar table (with no relationships)


Create this measure ...

Users for pickdate =
// get slicer pick date

VAR mypickdate = SELECTEDVALUE(Calendar[date])

// create subset of master records that are valid for the pickdate
VAR mysubset  =
FILTER(master,
master[startdate] <= mypickdate &&
master[enddate] >= mypickdate)


// return the sum of the users for the subset

RETURN
CALCULATE(

SUM( master[users]),
mysubset 
)

 

Create report with

 

dateslicer = Calendar[date]) with single selection turned on

 

client slicer = master[client]  with mutli selection turned on

 

A table visual with

 

  • master[client] 
  • [Users for pickdate]

 

This will work !

Please click thumbs up and accept as solution.

One problem per ticket please.

If you need to expan your problem then click accept as solution and raise a new ticket.

You willl get a quicker response and each solver gets the kudos they deserve. Thank you  😀

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.