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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
thomsontam
Frequent Visitor

Rolling Average Distinct count question

Hi,

 

I got a huge data set with 7m+ rows with the data like the following:

CompanyProductCountryUnitDate
1AAU11/07/2020
1BNZ11/07/2020
2ANZ11/07/2020
2BAU11/07/2020
3AAU11/07/2020
3CNZ11/07/2020
4BAU11/07/2020
5CAU11/07/2020
6AAU11/07/2020
6BAU11/07/2020
6CAU11/07/2020

 

I am able to create 90 Days running average on unit using the follow formula:

 

CALCULATE((Sum(table1[Unit]))/90,
DATESBETWEEN(table1[Date],
MAX(table1[Date]) - 89 ,
MAX(table1[Date]))

 

90 Days running average on customer count by

# of A  = 

Calculate(DistinctCount(Table1[Customer]),
FILTER(Table1,table1[Product]="A")
)

# of B = 

Calculate(DistinctCount(Table1[Customer]),
FILTER(Table1,table1[Product]="B")
)

 

# of A Avg 90D =
AVERAGEX(
DATESBETWEEN(table1[Date],
MAX(table1[Date]) - 89,
MAX(table1[Date])),table1[# of A]
)

 

# of B Avg 90D =
AVERAGEX(
DATESBETWEEN(table1[Date],
MAX(table1[Date]) - 89,
MAX(table1[Date])),table1[# of B]
)

 

A vs B Ratio 90D =
DIVIDE([# of A Avg 90D], [# of B Avg 90D])

 

All calculates are working on a small dataset but failed to load once data over 3m rows and took long time to refresh when change in filter.

 

Could you please give me some suggest how I should reformat the data ?

 

We need to do a lot of ratio analysis on product in difference country so I created a lot of individual measure for each product...

 

Thanks a lot!

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@thomsontam I wrote a series of blog posts on DAX Performance Optimization

https://community.powerbi.com/t5/Community-Blog/Performance-Tuning-DAX-Part-1/ba-p/976275

https://community.powerbi.com/t5/Community-Blog/Performance-Tuning-DAX-Part-2/ba-p/976813

 

Have you used the Performance Analyzer? 

Greg_Deckler_0-1599770149167.png

 

There is a series of best practices here for optimization:

https://maqsoftware.com/expertise/powerbi/dax-best-practices

 

There is great learning module available here:

https://docs.microsoft.com/en-us/learn/modules/optimize-model-power-bi/

 

Other than that, not sure I can assist. Didn't mean to link spam but performance optimization in DAX is a thick subject and would need your dataset to be specific!

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@thomsontam I wrote a series of blog posts on DAX Performance Optimization

https://community.powerbi.com/t5/Community-Blog/Performance-Tuning-DAX-Part-1/ba-p/976275

https://community.powerbi.com/t5/Community-Blog/Performance-Tuning-DAX-Part-2/ba-p/976813

 

Have you used the Performance Analyzer? 

Greg_Deckler_0-1599770149167.png

 

There is a series of best practices here for optimization:

https://maqsoftware.com/expertise/powerbi/dax-best-practices

 

There is great learning module available here:

https://docs.microsoft.com/en-us/learn/modules/optimize-model-power-bi/

 

Other than that, not sure I can assist. Didn't mean to link spam but performance optimization in DAX is a thick subject and would need your dataset to be specific!

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

After review my DAX from the suggestion in your link, found it was setup my filter incorrectly. 

Fix the filter and now only took 4 sec to recal rather then 4 mins.

Thanks!

 

amitchandak
Super User
Super User

@thomsontam , I am not sure it can give you a performance gain. But create a date table and join it with you table and do this calculation based on date table

 

try

Rolling 90 = CALCULATE(sum(table1[Unit]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-90,DAY))  //or 89

 

or

 

CALCULATE((Sum(table1[Unit]))/90,
DATESBETWEEN(Date[Date],
MAX(Date[Date]) - 89 ,
MAX(Date[Date]))

Or like This

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...


Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.