Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hi, so I'm new to PBI. Im using a 250k line db via excel, in which the data is about congress votations. I need to calculate de moving avrg but almost always there are more than one votation per day and many times a votation has several parts, so I think this is making it more dificult. I came before some DAX formulas and test them out I think I finaly found some thing that makes sense but the query is taking too long, about 700k ms. I think there is a way to optimize the query but Im having trouble knowing how. I use two columns [Data] (DATE) and [Custom] which is a binary count for Yes, No and Other Voting, Yes =1 , No and Other = 0.
Here is the DAX:
// DAX Query
DEFINE
VAR __DS0FilterTable =
TREATAS({"56ª Legislatura"}, '2022'[Legislatura])
VAR __DS0FilterTable2 =
TREATAS({"4ª Sessão Legislativa"}, '2022'[Sessão])
VAR __DS0FilterTable3 =
FILTER(
KEEPFILTERS(VALUES('2022'[Data])),
AND(
AND(
AND('2022'[Data] >= DATE(2022, 2, 4), '2022'[Data] < DATE(2023, 2, 4)),
'2022'[Data] >= DATE(2022, 11, 3)
),
'2022'[Data] < DATE(2022, 12, 22)
)
)
VAR __DS0Core =
SUMMARIZECOLUMNS(
'LocalDateTable_bd1749d9-de1f-435c-8a93-6bbfe052facc'[Year],
'LocalDateTable_bd1749d9-de1f-435c-8a93-6bbfe052facc'[Month],
'LocalDateTable_bd1749d9-de1f-435c-8a93-6bbfe052facc'[MonthNo],
'LocalDateTable_bd1749d9-de1f-435c-8a93-6bbfe052facc'[Day],
'2022'[Tema_parte],
__DS0FilterTable,
__DS0FilterTable2,
__DS0FilterTable3,
"AverageCustom", CALCULATE(AVERAGE('2022'[Custom])),
"Avg_Votes_MA_7_days", '2022'[Avg Votes (MA 7 days)]
)
VAR __DS0PrimaryWindowed =
TOPN(
1001,
__DS0Core,
'LocalDateTable_bd1749d9-de1f-435c-8a93-6bbfe052facc'[Year],
1,
'LocalDateTable_bd1749d9-de1f-435c-8a93-6bbfe052facc'[MonthNo],
1,
'LocalDateTable_bd1749d9-de1f-435c-8a93-6bbfe052facc'[Month],
1,
'LocalDateTable_bd1749d9-de1f-435c-8a93-6bbfe052facc'[Day],
1,
'2022'[Tema_parte],
1
)
EVALUATE
__DS0PrimaryWindowed
ORDER BY
'LocalDateTable_bd1749d9-de1f-435c-8a93-6bbfe052facc'[Year],
'LocalDateTable_bd1749d9-de1f-435c-8a93-6bbfe052facc'[MonthNo],
'LocalDateTable_bd1749d9-de1f-435c-8a93-6bbfe052facc'[Month],
'LocalDateTable_bd1749d9-de1f-435c-8a93-6bbfe052facc'[Day],
'2022'[Tema_parte]
Solved! Go to Solution.
So, just to close this question, aparently it was taking too long due to date hierarchy, I disabled that and leaved only date and that solved my problem.
So, just to close this question, aparently it was taking too long due to date hierarchy, I disabled that and leaved only date and that solved my problem.
@rogerrendon , check if you can window function for the same
Power BI Window function Rolling, Cumulative/Running Total, WTD, MTD, QTD, YTD, FYTD: https://youtu.be/nxc_IWl-tTc
Hi @amitchandak, so are you saying to substitue the VAR calculationperdiod? Instead of FILTER use WINDOW?
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
84 | |
72 | |
68 | |
41 | |
35 |
User | Count |
---|---|
109 | |
56 | |
52 | |
48 | |
42 |