Forum Discussion
singarfield
7 years agoHelper I
Create one date filter for three separate data sources
Hi everyone, I have three separate data sheets (excel) feeding into Power BI which all have the same date period in them, and I would like to be able to add one filter in my Power BI report which c...
- 7 years ago
let fnDateTable = (StartDate as date, EndDate as date, FYStartMonth as number) as table => let DayCount = Duration.Days(Duration.From(EndDate - StartDate)), Source = List.Dates(StartDate,DayCount,#duration(1,0,0,0)), TableFromList = Table.FromList(Source, Splitter.SplitByNothing()), ChangedType = Table.TransformColumnTypes(TableFromList,{{"Column1", type date}}), RenamedColumns = Table.RenameColumns(ChangedType,{{"Column1", "Date"}}), InsertYear = Table.AddColumn(RenamedColumns, "Year", each Date.Year([Date]),type text), InsertYearNumber = Table.AddColumn(RenamedColumns, "YearNumber", each Date.Year([Date])), InsertQuarter = Table.AddColumn(InsertYear, "QuarterOfYear", each Date.QuarterOfYear([Date])), InsertMonth = Table.AddColumn(InsertQuarter, "MonthOfYear", each Date.Month([Date]), type text), InsertDay = Table.AddColumn(InsertMonth, "DayOfMonth", each Date.Day([Date])), InsertDayInt = Table.AddColumn(InsertDay, "DateInt", each [Year] * 10000 + [MonthOfYear] * 100 + [DayOfMonth]), InsertMonthName = Table.AddColumn(InsertDayInt, "MonthName", each Date.ToText([Date], "MMMM"), type text), InsertCalendarMonth = Table.AddColumn(InsertMonthName, "MonthInCalendar", each (try(Text.Range([MonthName],0,3)) otherwise [MonthName]) & " " & Number.ToText([Year])), InsertCalendarQtr = Table.AddColumn(InsertCalendarMonth, "QuarterInCalendar", each "Q" & Number.ToText([QuarterOfYear]) & " " & Number.ToText([Year])), InsertDayWeek = Table.AddColumn(InsertCalendarQtr, "DayInWeek", each Date.DayOfWeek([Date])), InsertDayName = Table.AddColumn(InsertDayWeek, "DayOfWeekName", each Date.ToText([Date], "dddd"), type text), InsertWeekEnding = Table.AddColumn(InsertDayName, "WeekEnding", each Date.EndOfWeek([Date]), type date), InsertWeekNumber= Table.AddColumn(InsertWeekEnding, "Week Number", each Date.WeekOfYear([Date])), InsertMonthnYear = Table.AddColumn(InsertWeekNumber,"MonthnYear", each [Year] * 10000 + [MonthOfYear] * 100), InsertQuarternYear = Table.AddColumn(InsertMonthnYear,"QuarternYear", each [Year] * 10000 + [QuarterOfYear] * 100), ChangedType1 = Table.TransformColumnTypes(InsertQuarternYear,{{"QuarternYear", Int64.Type},{"Week Number", Int64.Type},{"Year", type text},{"MonthnYear", Int64.Type}, {"DateInt", Int64.Type}, {"DayOfMonth", Int64.Type}, {"MonthOfYear", Int64.Type}, {"QuarterOfYear", Int64.Type}, {"MonthInCalendar", type text}, {"QuarterInCalendar", type text}, {"DayInWeek", Int64.Type}}), InsertShortYear = Table.AddColumn(ChangedType1, "ShortYear", each Text.End(Text.From([Year]), 2), type text), AddFY = Table.AddColumn(InsertShortYear, "FY", each "FY"&(if [MonthOfYear]>=FYStartMonth then Text.From(Number.From([ShortYear])+1) else [ShortYear])) in AddFY in fnDateTableYou may want to paste this to your blank query. It is a date table with lots of column like mos, qtr, sem, etc. Got it from Enterprise DNA site. You can then create relationships to use only one filter for the three tables.
TomMartens
7 years agoSuper User
Hey, you can create an extra calendar table using DAX function CALENDARAUTO see here: https://dax.guide/calendarauto/
Create three relationship between the Calendartable on the one side and the other tables on the many side (make sure the cross filter direction is set to single).
Then you can create a slicer using the date column from the Calendar table, this will then filter all the other tables.
Hopefully this provides what you are looking for.
Regards,
Tom
Create three relationship between the Calendartable on the one side and the other tables on the many side (make sure the cross filter direction is set to single).
Then you can create a slicer using the date column from the Calendar table, this will then filter all the other tables.
Hopefully this provides what you are looking for.
Regards,
Tom
- singarfield7 years agoHelper I
Hi TomMartens ,
Thank you for your reply! I have not used DAX much. Do you know of any resource where I can look up how to do this?
Thank you,
- v-cherch-msft7 years agoMicrosoft Employee
Hi singarfield
You may have a look at below articles.
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://powerbi.tips/tag/calendarauto/
Regards,