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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
GillyGils
Frequent Visitor

LAG Conversion from MDX to DAX

Hi All,

I've the following MDX formula i'm trying to convert to DAX:

([Time Dimension].[Date].CurrentMember.lag(1), [Measures].[Total Available])

 

I've been trying to adjust the code below so I can retrieve the previous months 'Total Available' value but i'm only seem to be just getting the one singular previous month value:

PrevMonth = CALCULATE(
[Total Available],
ALLEXCEPT(TEST_TABLE,TEST_TABLE[DATE]),
DATEADD([DATE],-1,MONTH)
)

GillyGils_0-1665499799891.png

Any pointers would be appreciated.

Cheers

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @GillyGils ,

If there are only 'End of Month Dates' in your fact table. Please have a try.

Create a measure.

Measure1 = 
VAR _date =
MAX ( 'Table'[date] )
VAR _pre_date =
EOMONTH ( _date,-1)
VAR _value =
CALCULATE (
[total available],
FILTER ( ALL ( 'Table'), 'Table'[date] = _pre_date )
)
RETURN
_value

vpollymsft_0-1665624384281.png

Best Regards

Community Support Team _ Polly

 

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

4 REPLIES 4
GillyGils
Frequent Visitor

Hi Polly,

The code you provided is working for me as expected. I had use to EOMONTH, as I only have 'End of Month Dates' in my fact table:

 

Measure =
VAR _date =
MAX ( 'Table'[date] )
VAR _pre_date =
EOMONTH ( _date, -1 )
VAR _value =
CALCULATE (
[total available],
FILTER ( ALL ( 'Table'[date], 'Table'[total] ), 'Table'[date] = _pre_date )
)
RETURN
_value

 

GillyGils_0-1665592005513.png

One quick additonal question, when I drag in a Date Hierarchy of Time Dimension, the values are then empty:

GillyGils_1-1665592093779.png

Do I add another FILTER conidition to the DAX query?

 

Thanks

 

Anonymous
Not applicable

Hi @GillyGils ,

If there are only 'End of Month Dates' in your fact table. Please have a try.

Create a measure.

Measure1 = 
VAR _date =
MAX ( 'Table'[date] )
VAR _pre_date =
EOMONTH ( _date,-1)
VAR _value =
CALCULATE (
[total available],
FILTER ( ALL ( 'Table'), 'Table'[date] = _pre_date )
)
RETURN
_value

vpollymsft_0-1665624384281.png

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you Polly. This works perfectly.

Still getting a hang of the DAX syntax and this is helping me understand it more.

 

Thank you.

Anonymous
Not applicable

Hi @GillyGils ,

I have created a simple sample, please refer to it to see if it helps you.

Create a measure.

Measure =
VAR _date =
    MAX ( 'Table'[date] )
VAR _pre_date =
    EDATE ( _date, -1 )
VAR _value =
    CALCULATE (
        [total available],
        FILTER ( ALL ( 'Table'[date], 'Table'[total] ), 'Table'[date] = _pre_date )
    )
RETURN
    _value

 

vpollymsft_0-1665542703447.png

If I have misunderstood your meaning, please provide more details with your desired output and pbix file without  priavcy information.

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.