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
huqsami
Frequent Visitor

Row Based Time Intelligence for MAT

Hi There,

I got this awesome code from Phils Blog for Row Based Time Intelligence Slicer for Custom Period [Pased Bellow].

 

Now i need to come up with a code that will also include MAT [Moving Anual Total],

 

Could you please help me to modify the code? 

 

Thanks,

Sami

 

Time Intelligence =
VAR Today = MAX('Dim_Calendar'[Date])
VAR ThisYear = YEAR(Today)
VAR ThisMonth = MONTH(Today)
VAR ThisDay = DAY(Today)
RETURN
    SELECTCOLUMNS(
        UNION
            (
                // Last 3 Months
                ADDCOLUMNS(
                GENERATE(
                    SELECTCOLUMNS({"Last 3 Months"},"Period",[Value]) ,
                    GENERATESERIES(
                        DATE(ThisYear , ThisMonth - 3 , 1) ,
                        Today
                    )
                ),"Axis Date",[Value]),

                // Last 6 Months
                ADDCOLUMNS(
                GENERATE(
                    SELECTCOLUMNS({"Last 6 Months"},"Period",[Value]) ,
                    GENERATESERIES(
                        DATE(ThisYear , ThisMonth - 6 , 1) ,
                        Today
                    )
                ),"Axis Date",[Value]),

                // Current Year
                ADDCOLUMNS(
                GENERATE(
                    SELECTCOLUMNS({"Current Year"},"Period",[Value]) ,
                    GENERATESERIES(
                        DATE(ThisYear , 1 , 1) ,
                        Today
                    )
                ),"Axis Date",[Value]),

                // Prior Year
                ADDCOLUMNS(
                    GENERATE(
                    SELECTCOLUMNS({"Prior Year"},"Period",[Value]) ,
                    GENERATESERIES(
                            DATE(ThisYear-1 , 1 , 1) ,
                            DATE(ThisYear,ThisMonth-12,ThisDay)
                            )
                        ),
                    "Axis Date",DATE(YEAR([Value]),MONTH([Value])+12,DAY([Value])
                    )
                ),

               

                // Totals YTD
               
                    GENERATE(
                    SELECTCOLUMNS({"Totals YTD"},"Period",[Value]) ,
                    VAR BaseTable =
                        SELECTCOLUMNS(
                            GENERATESERIES(
                                DATE(ThisYear , 1 , 1) ,
                                Today
                                ),"D1",[Value]
                        )
                    RETURN
                        SELECTCOLUMNS(
                            GENERATE(
                                BaseTable ,
                                FILTER(
                                    SELECTCOLUMNS(BaseTable,"D2",[D1]) ,[D2]<=EARLIER([D1]))
                                )
                            ,"Date",[D2]
                            ,"Axis Date",[D1]
                        )
                    )
                       

                                       
               
            ) ,  
        "Date" , [Value] ,
        "Period" , [Period] ,
        "Axis Date" , [Axis Date]
    )    
1 ACCEPTED SOLUTION
huqsami
Frequent Visitor

I think i have figured, bellow code worked for me:

 

// MAT
                ADDCOLUMNS(
                    GENERATE(
                    SELECTCOLUMNS({"MAT"},"Period",[Value]) ,
                    GENERATESERIES(
                            DATE(ThisYear-1 ,ThisMonth, 1) ,
                            DATE(ThisYear,ThisMonth,ThisDay)
                            )
                        ),
                    "Axis Date",DATE(YEAR([Value]),MONTH([Value]),DAY([Value])
                    )
                ),

View solution in original post

1 REPLY 1
huqsami
Frequent Visitor

I think i have figured, bellow code worked for me:

 

// MAT
                ADDCOLUMNS(
                    GENERATE(
                    SELECTCOLUMNS({"MAT"},"Period",[Value]) ,
                    GENERATESERIES(
                            DATE(ThisYear-1 ,ThisMonth, 1) ,
                            DATE(ThisYear,ThisMonth,ThisDay)
                            )
                        ),
                    "Axis Date",DATE(YEAR([Value]),MONTH([Value]),DAY([Value])
                    )
                ),

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.

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.