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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.