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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
nbs33
Helper II
Helper II

Optimizing a simple moving average measure

Hi,

 

I have a Invoice Fact table with about 300,000 roles , 4 Dimension tables and a Date table with one to many relationships. I am trying to create a simple table with Invoice # and a column from each dimesion table.

 

It works fine until i add my measure below. Is there a way to optimize this measure?  It seem so simple that I shouldn't have this issue but I know DAX is complex and am hoping there is an obvious solution I am overlooking.

 

 

Revenue 12MM =
VAR revenue12mm = CALCULATE([SUM( Invoice[Revenue] ),
REMOVEFILTERS(Dates[Date]),
DATESINPERIOD(Dates[Date], LASTDATE(Invoice[ReportingDate]), -12, MONTH)
)
RETURN
IF( revenue12mm = 0, BLANK(), revenue12mm)

 

2 ACCEPTED SOLUTIONS
v-tangjie-msft
Community Support
Community Support

Hi  @nbs33 ,

 

According to your description, you want to calculate the previous year's revenue , right?

 

You can try to create a measure.

 

Revenue 12MM =

VAR revenue12mm = CALCULATE(SUM(Invoice[Revenue]), PARALLELPERIOD(Dates[Date],-1,year))  

RETURN

IF( revenue12mm = 0, BLANK(), revenue12mm)

 

For more information about the function you can refer to the following documents.

PARALLELPERIOD function (DAX) - DAX | Microsoft Learn

 

Best Regards,

Neeko Tang

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

nbs33
Helper II
Helper II

After a lot of trial and error and looking at the query analizer I relized most of the time was spent joining the dimension tables to the fact table. 

 

To overcome this I colapsed the necessary columns of my demnsion table into may fact table and this greatly improved performance. 

View solution in original post

5 REPLIES 5
nbs33
Helper II
Helper II

After a lot of trial and error and looking at the query analizer I relized most of the time was spent joining the dimension tables to the fact table. 

 

To overcome this I colapsed the necessary columns of my demnsion table into may fact table and this greatly improved performance. 

v-tangjie-msft
Community Support
Community Support

Hi  @nbs33 ,

 

According to your description, you want to calculate the previous year's revenue , right?

 

You can try to create a measure.

 

Revenue 12MM =

VAR revenue12mm = CALCULATE(SUM(Invoice[Revenue]), PARALLELPERIOD(Dates[Date],-1,year))  

RETURN

IF( revenue12mm = 0, BLANK(), revenue12mm)

 

For more information about the function you can refer to the following documents.

PARALLELPERIOD function (DAX) - DAX | Microsoft Learn

 

Best Regards,

Neeko Tang

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

tamerj1
Super User
Super User

Hi @nbs33 

try to replace LASTDATE with MAX

Hi @nbs33 ,

 

Has your problem been solved?If the problem has been solved you can mark the reply for the standard answer to help the other members find it more quickly. If not, please point it out.

 

Best Regards,

Neeko Tang

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

Hi @tamerj1 thanks for the help. It didn't work. Could it be realted to DATESINPERIOD?

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Kudoed Authors