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
Anonymous
Not applicable

Migrating MDX code to DAX: lag functions and tuples

 

I have to port some MDX formulas to DAX, in order to move from Pentaho to Power BI. I have been all day trying to change these formulas but I am not getting any progress, my main problems now are with these two formulas:

%succes=Avg([Fecha Oferta.Mes].CurrentMember.Lag(11):[Fecha Oferta.Mes].CurrentMember,[Measures].[Importe Neto Factura]/[Measures].[Importe Neto Oferta])


futureBenefits=[Measures].[Net Offer quantity]*Avg([Date Offer.Month].CurrentMember.Lag(11):[Date offer.month].CurrentMember,[Measures].[% Exito de Of en Fras (Importe)])

After that I have to display them in a matrix, separated by years and months I have been trying to use things like this:

AVERAGEX(FILTER(offers;DATEADD(dim_time[date];-1;YEAR));SUM(offers[net_quantity_ticket])/SUM(offers[net_quantity_offer]))

But it is not working, I just get the same results that I get using this:

AVERAGEX(offers;SUM(offers[net_quantity_ticket])/SUM(offers[net_quantity_offer]))

I have also tried using CALCULATE instead of AVERAGEX +FILTER but it does not even get accepted because average needs a column, not a measure. Any suggestions about how could I translate this code? Sorry but I cannot post any data since it is confidential
Thanks a lot for your help

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@Anonymous,

 

You may view the code generated by Quick measure Rolling average.

Community Support Team _ Sam Zha
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

2 REPLIES 2
v-chuncz-msft
Community Support
Community Support

@Anonymous,

 

You may view the code generated by Quick measure Rolling average.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thanks, that was what I needed, I ended up with code looking like this:

 
% success =
IF(
    ISFILTERED('dim_time'[date]);
    ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column.");
    VAR __LAST_DATE = ENDOFMONTH('dim_time'[date].[Date])
    VAR __DATE_PERIOD =
        DATESBETWEEN(
            'dim_time'[date].[Date];
            STARTOFMONTH(DATEADD(__LAST_DATE; -11; MONTH));
            __LAST_DATE
        )
    RETURN
        AVERAGEX(
            CALCULATETABLE(
                SUMMARIZE(
                    VALUES('dim_time');
                    'dim_time'[date].[Year];
                    'dim_time'[date].[QuarterNo];
                    'dim_time'[date].[Quarter];
                    'dim_time'[date].[MonthNo];
                    'dim_time'[date].[Month]
                );
                __DATE_PERIOD
            );
            CALCULATE([% success(Importe)]; ALL('dim_time'[date].[Day]))
        )
)
 
Thanks again!

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.