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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
huqsami
Regular Visitor

Row Based Time Intelligence QTD

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 QTD [Quarter to Date],

 

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 REPLY 1
amitchandak
Super User
Super User

@huqsami , You min and max values for QTD are

 

var _max1 = today()
var _max = eomonth(_max1,-1* if( mod(Month(_max1),3) =0,3,Month(_max1)))
var _min = eomonth(_min,-3)+1

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.