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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
wmeads001
Regular Visitor

Dynamic calendar

Hi   I am trying to create a dynamic calendar at the Month level (There is no need for day level)  I have created a master calendar with no problem and I am now trying to create the Dynamic period filter table that will link to the Master calendar and filters can be applied to the required monthly periods in a visualisation

 

The dynamic period filter table will look like this.  (Only some values shown)

 

Expected outcome for a sample of Periods
BasePeriod  PeriodMeasure  PeriodKey
201901        YTD                   201901
201902        YTD                   201901
201902        YTD                   201902
201903        YTD                   201901
201903        YTD                   201902
210903        YTD                   201903
201904        YTD                   201901
201904        YTD                   201902
201904        YTD                   201903
201904        YTD                   201904
201901        Last Year YTD   201801
201902        Last Year YTD   201801
201902        Last Year YTD   201802
201903        Last Year YTD   201801
201903        Last Year YTD   201802
201903        Last Year YTD   201803
202002        Last 3 months  201912
202002        Last 3 months  202001
202002        Last 3 months  202002
202003        Last 3 months  202001
202003        Last 3 months  202002
202003        Last 3 months  202003

 

I am able to generate the PeriodKey for a number of PeriodMeasures using a fixed BasePeriod using this Dax

 

PeriodMeasureFilter =
VAR Today = Date(2018,05,01)
//VAR Today = Date(StartYear,01,01)
VAR ThisYear = YEAR(Today) //Date(StartYear,01,01))
VAR ThisMonth = MONTH(Today)
VAR ThisPeriod = ThisYear *100 + ThisMonth
VAR MinMonth = YEAR(DATE(StartYear,01,01)) *100 +MONTH(01)
VAR MaxMonth = YEAR(DATE(EndYear,12,31)) *100 +MONTH(12)

RETURN
SELECTCOLUMNS(
UNION(
// Last 2 Months
ADDCOLUMNS(
GENERATE(
SELECTCOLUMNS({"Last 2 Months"}, "PeriodMeasure",[Value]) ,
GENERATESERIES(
ThisYear*100 + ThisMonth-1,
ThisYear*100 + ThisMonth)
),"PeriodKey" , [Value] , "BasePeriod" , ThisPeriod )
,
 
// Last 3 Months
ADDCOLUMNS(
GENERATE(
SELECTCOLUMNS({"Last 3 Months"},"PeriodMeasure",[Value]) ,
GENERATESERIES(
// DATE(ThisYear , ThisMonth - 2 , 1) ,
ThisYear*100 + ThisMonth-2,
ThisYear*100 + thisMonth)
),"PeriodKey",[Value],"BasePeriod", ThisPeriod )
,

// Current Year
ADDCOLUMNS(
GENERATE(
SELECTCOLUMNS({"Current Year"},"PeriodMeasure",[Value]) ,
GENERATESERIES(
ThisYear*100 + 01 ,
ThisYear*100 +ThisMonth)
),"PeriodKey",[Value],"BasePeriod",ThisPeriod)
,

// Prior Year
ADDCOLUMNS(
GENERATE(
SELECTCOLUMNS({"Prior Year"},"PeriodMeasure",[Value]) ,
GENERATESERIES(
(ThisYear -1)*100 + 01,
(ThisYear -1)*100 + ThisMonth )
),"PeriodKey",[Value],"BasePeriod",ThisPeriod )
,
 
//YTD
ADDCOLUMNS(
GENERATE(
SELECTCOLUMNS({"YTD"},"PeriodMeasure",[Value]) ,
GENERATESERIES(
ThisYear*100 + 01,
ThisYear*100 + ThisMonth )
),"PeriodKey",[Value],"BasePeriod",ThisPeriod )
 
) ,
"BasePeriod" , [BasePeriod] ,
"PeriodKey" , [PeriodKey] ,
"PeriodMeasure" , [PeriodMeasure]
)
 

 

I would like to generate all the PeriodKey's for all the PeriodMeasure,s for all the BasePeriod's between the first period in StartYear and the end period in Endyear which are two paramaters used to generate the main Calender file

 

Any help would be appreciated.

 

3 REPLIES 3
amitchandak
Super User
Super User

What is objective of this calendar. Are you trying to YTD, LYD or rolling months? Can time intelligence help you in that?

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@wmeads001 ,if you need more help make me @

Appreciate your Kudos.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Greg_Deckler
Super User
Super User

So you want the first table displayed between StartYear and EndYear and you want Base Periods

 

Table = 
  VAR __Years = GENERATESERIES([StartYear],[EndYear],1)
  VAR __Months = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12")
  VAR __Table = 
    ADDCOLUMNS(
      GENERATE(__Years,__Months)
      "__Base Period",[Value1] & [Value2]
    )
RETURN
  SELECTCOLUMNS(__Table,"Base Period",[__Base Period])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.