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

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

Reply
Anonymous
Not applicable

INDIRECT function in DAX

Hi all,

I have a problem. I want to create a dynamic measure in DAX that will depend of the name of the variable.

I have a table with column names display like this Month 1, Month 2,..... Month n, now depending of the current month or the selected month , the formula will display the value of the month selected and the one of the previous month. I want a formula like this SUM(Month n) + SUM (Month n-1). This is possible in Excel using INDIRECT function, what about DAX!!!!

 

Thank you

3 REPLIES 3
Anonymous
Not applicable

Hi. did you find a DAX function similar to "indirect" in Excel? I've been search the net but no success yet. Would appreciate your feedback.

Ashish_Mathur
Super User
Super User

Hi,

Assuming you have a Calendar table with Year and Month columns in there, build a relationship from the Date column of your Data Table to the Date column of the Calendar Table.  Create 2 slicers - one for Year and another for Month - select any one Year and Month.  Write these measures

Total = SUM(Data[Amount])

Total for this and previous month = CALCULATE([Total],DATESBETWEEN(Calendar[Date],EDATE(MIN(Calendar[Date]),-1),MAX(Calendar[Date])))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
MFelix
Super User
Super User

Hi @Anonymous ,

 

I'm assuming that your data is on the format like below:

 

KPI 1 2 3 4 5 6
Value 1 1 1 1 1 1

 

If this is the case believe that the best option is to unpivot the table and have something like this:

 

KPI Month Value
Value 1 1
Value 2 2
Value 3 3
Value 4 4
Value 5 5
Value 6 6

 

Then you can create a measure similar to this:

Total 2 month =
CALCULATE ( SUM ( Table1[Value] ) )
    + CALCULATE (
        SUM ( Table1[Value] );
        FILTER ( ALL ( Table1[Month] ); Table1[Month] = ( MAX ( Table1[Month] ) - 1 ) )
    )

If you don't want to unpivot your columns then you need to do it using several measures and a switch function.

 

Can you share a sample of you data and expected result.

 

thank you.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.