Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Is there a way to optimize the performance of below query
Sale from Current Inventory Balance NY =
VAR CurrentDate =
TODAY ()
VAR InitialValue = [Opening Bal]
VAR CurrentYear =
YEAR ( CurrentDate )
RETURN
SUMX (
FILTER (
ADDCOLUMNS (
CALENDAR ( TODAY (), DATE ( YEAR ( TODAY () ) + 1, 12, 31 ) ),
"DaysSinceStart", DATEDIFF ( CurrentDate, [Date], DAY ),
"DailyValueSub",
IF (
DATEDIFF ( CurrentDate, [Date], DAY ) < 'Day Range'[Day Range Value],
DIVIDE ( [Opening Bal], 'Day Range'[Day Range Value] )
)
),
[Date] >= CurrentDate
&& YEAR ( [Date] )
= YEAR ( TODAY () ) + 1
),
[DailyValueSub]
)
Solved! Go to Solution.
Hi @Antmkjr
Here are some suggestions to optimize your query:
Here’s an optimized version (1) of your query, you could try this:
SaleFromCurrentInventoryBalanceNY =
VAR CurrentDate = TODAY()
VAR InitialValue = [Opening Bal]
VAR CurrentYear = YEAR(CurrentDate)
VAR EndDate = DATE(CurrentYear + 1, 12, 31)
VAR DateRange = CALENDAR(CurrentDate, EndDate)
RETURN
SUMX(
FILTER(
ADDCOLUMNS(
DateRange,
"DaysSinceStart", DATEDIFF(CurrentDate, [Date], DAY),
"DailyValueSub",
IF(
DATEDIFF(CurrentDate, [Date], DAY) < 'Day Range'[Day Range Value],
DIVIDE(InitialValue, 'Day Range'[Day Range Value])
)
),
[Date] >= CurrentDate && YEAR([Date]) = CurrentYear + 1
),
[DailyValueSub]
)
Version 2:
SaleFromCurrentInventoryBalanceNY =
VAR CurrentDate = TODAY()
VAR InitialValue = [Opening Bal]
VAR CurrentYear = YEAR(CurrentDate)
VAR EndDate = DATE(CurrentYear + 1, 12, 31)
VAR DateRange = CALENDAR(CurrentDate, EndDate)
VAR FilteredDates =
FILTER(
DateRange,
[Date] >= CurrentDate && YEAR([Date]) = CurrentYear + 1
)
VAR CalculatedValues =
ADDCOLUMNS(
FilteredDates,
"DaysSinceStart", DATEDIFF(CurrentDate, [Date], DAY),
"DailyValueSub",
IF(
DATEDIFF(CurrentDate, [Date], DAY) < 'Day Range'[Day Range Value],
DIVIDE(InitialValue, 'Day Range'[Day Range Value])
)
)
RETURN
SUMX(
CalculatedValues,
[DailyValueSub]
)
Hope this helps!!
If this solved your problem, please accept it as a solution and a kudos!!
Best Regards,
Shahariar Hafiz
Hi @Antmkjr
Here are some suggestions to optimize your query:
Here’s an optimized version (1) of your query, you could try this:
SaleFromCurrentInventoryBalanceNY =
VAR CurrentDate = TODAY()
VAR InitialValue = [Opening Bal]
VAR CurrentYear = YEAR(CurrentDate)
VAR EndDate = DATE(CurrentYear + 1, 12, 31)
VAR DateRange = CALENDAR(CurrentDate, EndDate)
RETURN
SUMX(
FILTER(
ADDCOLUMNS(
DateRange,
"DaysSinceStart", DATEDIFF(CurrentDate, [Date], DAY),
"DailyValueSub",
IF(
DATEDIFF(CurrentDate, [Date], DAY) < 'Day Range'[Day Range Value],
DIVIDE(InitialValue, 'Day Range'[Day Range Value])
)
),
[Date] >= CurrentDate && YEAR([Date]) = CurrentYear + 1
),
[DailyValueSub]
)
Version 2:
SaleFromCurrentInventoryBalanceNY =
VAR CurrentDate = TODAY()
VAR InitialValue = [Opening Bal]
VAR CurrentYear = YEAR(CurrentDate)
VAR EndDate = DATE(CurrentYear + 1, 12, 31)
VAR DateRange = CALENDAR(CurrentDate, EndDate)
VAR FilteredDates =
FILTER(
DateRange,
[Date] >= CurrentDate && YEAR([Date]) = CurrentYear + 1
)
VAR CalculatedValues =
ADDCOLUMNS(
FilteredDates,
"DaysSinceStart", DATEDIFF(CurrentDate, [Date], DAY),
"DailyValueSub",
IF(
DATEDIFF(CurrentDate, [Date], DAY) < 'Day Range'[Day Range Value],
DIVIDE(InitialValue, 'Day Range'[Day Range Value])
)
)
RETURN
SUMX(
CalculatedValues,
[DailyValueSub]
)
Hope this helps!!
If this solved your problem, please accept it as a solution and a kudos!!
Best Regards,
Shahariar Hafiz
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 20 | |
| 11 | |
| 10 | |
| 4 | |
| 4 |
| User | Count |
|---|---|
| 32 | |
| 28 | |
| 19 | |
| 11 | |
| 10 |