Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.
Hi,
I have been struggling with this issue for a while. I am a fact table of about 2.5 million rows and multiple dimension tables, the largest being a cusotmer table of about 165,000 rows. I also have a date table.
I was able to analyze the query and find that the majority of the time was takening up joining the Cusotmer Dim to the Date Dim. ( 165,000 cusotmer x 365 days ( see query below) = aprox. 58 million records).
Orginal Measure:
Original Revenue 12MM =
VAR revenue12mm = CALCULATE( SUM( Fact[Revenue] ),
REMOVEFILTERS(Dates[Date]),
DATESINPERIOD(Dates[Date], LASTDATE(Invoice[ReportingDate]), -12, MONTH)
)
RETURN
revenue12mm
I was about to reduce the cardinality in my fact table by reducing he the reporting date to a monthly value ( mm/01/yyyy) and found better performance by not using the DATESINPERIOD.
Optimized Revenue 12MM =
VAR MaxDate = CALCULATE( SELECTEDVALUE( Dates[Month Year] ), Dates[Date] = MAX(Fact[ReportingDate]) )
VAR MinDate = DATE( YEAR( MaxDate )-1 , MONTH( MaxDate ) +1, 1)
VAR revenue12mm =
CALCULATE( SUM( Fact[Revenue]),
Fact[ReportingDate] <= MaxDate &&
Fact[ReportingDate] >= MinDate
)
RETURN
revenue12mm
This optimized query runs in about 16 seconds but it is still painfully slow. It seems like the majority of time still spent with the join on Customer and Date. It is down to 1.4 million rows.
Any ideas how to improve this?
Hi @nbs33 ,
Can I ask why you are trying to filter on MAX(Fact[ReportingDate]?
If you are looking for YTD, could you just use TOTALYTD function?
Hi @djurecicK2 thank you for your input. I am not sure what you are refereing to. The the YTD functions work well. The two 12MM measurse are the slow ones. Are you refering to these measures?
@daXtreme & @amitchandak I apprciate both of your inputs.
I have created a stripped down dataset so you can see issue first hand. ( pbix File )
The performance is improved in the sample after removing the majority of columns but the main issue still presists.
From what I can tell if specific to them Revenue 12MM and Premium 12 MM measures.
I am only in the begining of my learnings about DAX optimization so you insights are greatly appreciated.
Hi @nbs33,
Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.
If these also don't help, please share more detailed information to help us clarify your scenario to test.
How to Get Your Question Answered Quickly
Regards,
Xiaoxin Sheng
It's literally not possible to optimize code without having the model and data in front of the eyes. Supply some data to play with (representative!) and then we can talk. Also, the hardware plays a role in how fast your DAX is gonna work on big models.
@nbs33 , the second one seems better, You can mark the join column as key column
try this one
rolling 12 =
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _min = date(Year(_max), month(_max) -12, Day(_max))+1
BLANK())
return
CALCULATE(SUM( Fact[Revenue]) ,DATESBETWEEN('Date'[Date],_min,_max))
Original Revenue 12MM =
CALCULATE( SUM( Fact[Revenue] ),
DATESINPERIOD(Dates[Date], LASTDATE(Invoice[ReportingDate]), -12, MONTH)
)
Check out the November 2023 Power BI update to learn about new features.
Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.
Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!