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
dmeadway
New Member

DAX Measure - Current Week Amount

I have created a dax measure to calculate the Current Overdue Amount for each customer in a table. The measure is formulated as follows:

=VAR CurrDate = MAX('f_AR_Trend'[AS OF DATE])

VAR CurrOD = CALCULATE([Total Overdue], f_AR_Trend[AS OF DATE] = CurrDate)

 

RETURN

CurrOD

The issue I am having is this formula is returning the value of the PrevDate (i.e. If 3/17/2024 is the most recent "As Of Date" and 3/3/2024 is the next most recent "As Of Date") as part of the Current Overdue Amount measure. How do I write the formula to fill in a zero instead of the amount from 3/3 if a customer had on overdue amount on 3/3, but did not have any amount on 3/17?

dmeadway_0-1711633821825.png

dmeadway_2-1711634040551.png

 

The Table structure is as follows (simplified for the fields the measure uses):

AS OF DATECustomerTotal Overdue
3/3/2024A28,685
3/3/2024B5,877
3/17/2024A 
3/17/2024B 
2 ACCEPTED SOLUTIONS

v-xuxinyi-msft
Community Support
Community Support

Hi @dmeadway 

 

Your solution is great, @lbendlin. It worked like a charm! Here I have another idea in mind, and I would like to share it for reference.

 

I created serval measures as follow.

AS = MAX([AS OF DATE])
rank = RANKX(ALLEXCEPT(Source, Source[Customer]), [AS], , DESC, Dense)
Current Date = 
VAR _total = CALCULATE(MAX([Total Overdue]), FILTER(Source, [AS OF DATE] = SELECTEDVALUE('Table'[Date])))
RETURN
IF(_total = BLANK(), 0, _total)
Previous Date = 
VAR _rank = MAXX(FILTER(Source, [AS OF DATE] = SELECTEDVALUE('Table'[Date])), [rank])
VAR _lastdate = CALCULATE(MAX([AS OF DATE]), FILTER(ALL(Source), [rank] = 2))
VAR _total = CALCULATE(MAX([Total Overdue]), FILTER(ALLEXCEPT(Source, Source[Customer]), [AS OF DATE] = _lastdate))
RETURN
IF(_total = 0, 0, MAX([Total Overdue]))

 

Result:

vxuxinyimsft_0-1711964193560.png

 

Best Regards,
Yulia Xu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-xuxinyi-msft
Community Support
Community Support

Hi @dmeadway 

 

Your solution is great, @lbendlin. It worked like a charm! Here I have another idea in mind, and I would like to share it for reference.

 

I created serval measures as follow.

AS = MAX([AS OF DATE])
rank = RANKX(ALLEXCEPT(Source, Source[Customer]), [AS], , DESC, Dense)
Current Date = 
VAR _total = CALCULATE(MAX([Total Overdue]), FILTER(Source, [AS OF DATE] = SELECTEDVALUE('Table'[Date])))
RETURN
IF(_total = BLANK(), 0, _total)
Previous Date = 
VAR _rank = MAXX(FILTER(Source, [AS OF DATE] = SELECTEDVALUE('Table'[Date])), [rank])
VAR _lastdate = CALCULATE(MAX([AS OF DATE]), FILTER(ALL(Source), [rank] = 2))
VAR _total = CALCULATE(MAX([Total Overdue]), FILTER(ALLEXCEPT(Source, Source[Customer]), [AS OF DATE] = _lastdate))
RETURN
IF(_total = 0, 0, MAX([Total Overdue]))

 

Result:

vxuxinyimsft_0-1711964193560.png

 

Best Regards,
Yulia Xu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

Are you expecting to see 0 (zero)  for both accounts?  You can either fudge your measure with the "+0"  hack, or use COALESCE(measure,0)

The goal would be to have a zero return if a customer has no data for the current max date. Same concept for the previous.

Source Table

AS OF DATECustomerTotal Overdue
3/3/2024A28,685
3/3/2024B5,877
3/3/2024C1,000
3/17/2024C500
2/25/2024D2,000
3/17/2024D3,000
2/20/2024E1,000
2/25/2024E1,500

 

Below is the output I would want to see. I want to compare the two most recent dates within my table for all customers in my data set. If it didn't have activity on the two most recent dates the output should be zero. If it had activity on the current, but not on the previous then the output should be the amount for the current and zero for previous and vice versa. 

End Result

CustomerCurrent DatePrevious Date
A028,685
B05,877
C5001,000
D3,0000
E00

 

lbendlin_0-1711665463860.png

 

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.