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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Markando
Frequent Visitor

Optimize rolling 12 formula

Hi Guys

 

I've created a dax formula for calculating a rolling 12 sum of [belopp tUSD]. The table contains data from 2016-04-01 and I have two conditions for the report: 

 

* only show the R12-value if there is 12 months worth of data to measure

* dont show the R12-value if there isnt any monthly data available (dont want to measure the future R12)

 

The formula below works fine, however the table is going to be huge so I want to optimize the report for speed, I get the feeling having two IF-checks isnt ideal. Any suggestions for improvement is highly appreciated as I'm very new to the coding. 

 

ex report.JPG

 

First IF, check if the number of "monthname" is below <12

second IF, check if the montly sum = blank(), then return blank for the R12-measure

 

tUSD R12:=
IF(
CALCULATE(
COUNTROWS(VALUES(calender[MonthName]));
datesbetween(calender[Datum];
CALCULATE(firstdate(ALL(Levreskontra[InvoiceDate]));Levreskontra[Currency]="USD");
LASTDATE(calender[Datum]))
)
<12;BLANK();

 

IF([Belopp tUSD]=BLANK();BLANK();
calculate([Belopp tUSD];
datesbetween(calender[Datum];
NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE (calender[Datum])));
LASTDATE(calender[Datum]))))
)

 

1 REPLY 1
Eric_Zhang
Employee
Employee

@Markando

You can just try to wrap the two IF into one, thought I don't think it won't make much difference. Any acutally performance issue you've encountered?

tUSD R12 :=
IF (
    CALCULATE (
        COUNTROWS ( VALUES ( calender[MonthName] ) ),
        DATESBETWEEN (
            calender[Datum],
            CALCULATE (
                FIRSTDATE ( ALL ( Levreskontra[InvoiceDate] ) ),
                Levreskontra[Currency] = "USD"
            ),
            LASTDATE ( calender[Datum] )
        )
    )
        < 12
        || [Belopp tUSD] = BLANK (),
    BLANK (),
    CALCULATE (
        [Belopp tUSD],
        DATESBETWEEN (
            calender[Datum],
            NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( calender[Datum] ) ) ),
            LASTDATE ( calender[Datum] )
        )
    )
)

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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