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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.