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
NandhiniE31
Frequent Visitor

Sum(amount) for Account ids there on Yesterday but those account ids do not exist day before yesterd

Hi, 

 

I have issue with a DAX where I have to find total sales for account IDs not present Day-2( Day before yesterday) but present Day-1 (Yesterday) based on date from filter. 

 

Table Structure: ACCOUNT_ID ,DATE, SALES AMOUNT

 

Sample Table: 

DateAcc_IDSalesAmount
19-12-2017110
18-12-2017120
19-12-2017210
19-12-2017350
17-12-20174100
19-12-2017440
18-12-2017425
17-12-2017115

 

Example: if the date selected is 20/12/2017 , Sum of sales amount should be 60.

1 ACCEPTED SOLUTION
AnkitBI
Solution Sage
Solution Sage

I have come up with below. Please check. I have created a new date table for slicing. You can modify DAX if you don't have any date table with you.

Capture.PNG

Measure 3 = 
var p1 =  FILTER(all(Table1),Table1[Date] = SELECTEDVALUE(Table3[Day]) - 1)
var r1 = SELECTCOLUMNS(p1,"acct",Table1[Acc_ID])
var p2 = FILTER(all(Table1),Table1[Date] = SELECTEDVALUE(Table3[Day]) - 2)
var r2 = SELECTCOLUMNS(p2,"acct",Table1[Acc_ID])
var r3 = EXCEPT(r1,r2)
var r4 = CALCULATE(sum(Table1[SalesAmount]),filter(all(table1),Table1[Acc_ID] in distinct(r3) && Table1[Date] = SELECTEDVALUE(Table3[Day]) - 1 ))
return 
r4

 

 

 

View solution in original post

1 REPLY 1
AnkitBI
Solution Sage
Solution Sage

I have come up with below. Please check. I have created a new date table for slicing. You can modify DAX if you don't have any date table with you.

Capture.PNG

Measure 3 = 
var p1 =  FILTER(all(Table1),Table1[Date] = SELECTEDVALUE(Table3[Day]) - 1)
var r1 = SELECTCOLUMNS(p1,"acct",Table1[Acc_ID])
var p2 = FILTER(all(Table1),Table1[Date] = SELECTEDVALUE(Table3[Day]) - 2)
var r2 = SELECTCOLUMNS(p2,"acct",Table1[Acc_ID])
var r3 = EXCEPT(r1,r2)
var r4 = CALCULATE(sum(Table1[SalesAmount]),filter(all(table1),Table1[Acc_ID] in distinct(r3) && Table1[Date] = SELECTEDVALUE(Table3[Day]) - 1 ))
return 
r4

 

 

 

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.