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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
huqsami
Regular 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
Regular 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
Regular 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

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

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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