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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
aeid101
New Member

DAX Time Intelligence with Conditional Logic

 I have a "sales" table with team ID, payment type and date (see example below):

 

 

Time Intel.PNG

 

I want to write a DAX formula that will "lookup" the prior month's sales amount for a "Monthly" team and the 3 month prior sales amount for a "Quarterly" team. The lookup also needs to be filtered by team ID, so the prior sales belong to the same team.

Here's an example of the desired output (Change in Sales) :

 

Time Intel 2.PNG

 

 

PriorMonthSales =CALCULATE(
SUM(Table[Sales]),
FILTER(
   Table[TeamID]&&
   Table[Date] - 1
 )

PriorQuarterSales =CALCULATE(
SUM(Table[Sales]),
FILTER(
   Table[TeamID]&&
   Table[Date] - 3
 )

PriorSales = IF(Table[PaymentType] = "Monthly",PriorMonthSales,   PriorQuarterSales)

These formulas obviously don't produce the desired result, but I am sharing them here to show my approach to solving this. Perhaps, someone more knowledgeable here can assist with the correct syntax and logic.

Thanks!

3 REPLIES 3
v-qiuyu-msft
Community Support
Community Support

Hi @aeid101,

 

In your scenario, please follow steps below to calculate the difference for sales within each Team ID instance:

 

1. Return previous date within each Team ID group instance.

 

a1.PNG

 

2. Return previous sales within each Team ID group instance.

a2.PNG

 

3. Calculate teh difference between each row within each Team ID instance.

a3.PNG

 

Reference:

PowerPivot DAX Session Notes 2 – Previous Row

 

If you have any question, please feel free to ask.

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
achinm45
Advocate IV
Advocate IV

Hi @aeid101

 

Try this attached screenshot

 

PreviousMonthAmountPreviousMonthAmount

 

 

MattAllington
Community Champion
Community Champion

Do you have a calendar table?  It doesn't look like it.  I suggest you read my article about calendar tables here. 

 

http://exceleratorbi.com.au/power-pivot-calendar-tables/

 

It looks like a monthly calendar table will work for you. Make sure you have an ID column and then you can write your filter function to operate on the ID column. 

 

Post back if that doesn't make sense



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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