cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rachaelwalker
Resolver II
Resolver II

Group data by Week and on Mondays

I am trying to group data by week/Mondays. I have a date data table and another data table called iAuditor Reports. On the date table I have a "week starting" column to calculate Mondays using the following formula

 

Week Starting = IF(WEEKDAY('Query2'[Date],2)=1,'Query2'[Date],DATEADD('Query2'[Date],-WEEKDAY('Query2'[Date],2)+1,DAY))

 

The tables are related using the date field

 

however when I created a basic bar graph or table visual, it doesn't appear that they are related (right visual) The visual on the left is only using data from iauditor table. The visual on the right is using data from both tables

 

power bi visuals.png

table.png

 

Is there a formula I need to use to create a start week/monday column in my iauditor table? Sorry in advance if I explained that horribly.  I am a beginner.

2 ACCEPTED SOLUTIONS

@parry2k I sent you a link to your email

View solution in original post

@parry2k Thank you for taking the time to resolve this issue. Thankful it was an easy fix and appreciate everyone taking the time.

 

Resolution: Date field in the iauditor table was not set to "Date" data type. 

View solution in original post

15 REPLIES 15
v-zhenbw-msft
Community Support
Community Support

Hi @rachaelwalker ,

 

Please check your date table, whether it starts on Monday.

If it does not start on Monday, then the Week column will have a blank value, like the following screen shot.

 

G1.jpg

 

G2.jpg

 

Maybe you refer this method, create a calculate column to get the min date of each week.

 

1. Create a year column and weeknum column in date table.

 

Year = YEAR(Query2[Date])
weeknum = WEEKNUM(Query2[Date],2)

 

G3.jpg

 

2. Then create a new week starting column.

 

New Week starting = CALCULATE(MIN(Query2[Date]),FILTER(Query2,Query2[weeknum]=EARLIER(Query2[weeknum]) && Query2[Year]=EARLIER(Query2[Year])))

 

G4.jpg

 

3. At last create a many-to-one relationship between fact table and date table.

 

G5.jpg

 

G6.jpg

 

If it doesn’t meet your requirement, could you please provide a mockup sample based on fake data or describe the fields of each tables and the relations between tables simply?

 

It will be helpful if you can show us the exact expected result based on the tables.

Please upload your files to OneDrive For Business and share the link here. Please don't contain any Confidential Information or Real data in your reply.

 

Best regards,

 

Community Support Team _ zhenbw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.


BTW, pbix as attached.

parry2k
Super User
Super User

@rachaelwalker can you share the relationship between these two tables? 






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





@rachaelwalker this is weird, can you change cross filter direction to single, instead of both. It is not recommended to have relationship direction to both.  






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





I changed the cross filter and it appears the same

@rachaelwalker does your calendar table have all the dates, for the year 2020.

 

Check this post for the calendar table, although you already have but make sure you have dates in the calendar table to cover the auditor's table dates.

https://perytus.com/2020/05/22/create-a-basic-date-table-in-your-data-model-for-time-intelligence-ca...

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





@parry2k yes it has all dates up to 2025. Would it be how I have my date table setup? I created a custom function (query 1) and another custom query to call query one for the dates

 

custom fx - query 1

 

= (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

 

 

custom query 2 (this is what creates the date table. I then added a column for week start using the formula in my original post)

= Query1(#date(2019, 1, 1), #date(2025, 12, 31), 10)

 

@rachaelwalker it shouldn't matter how you created the date table? Are you open to send pbix file, remove sensitive information before sharing, if that is not possible then we can have a goto meeting/zoom call and look into it. I will be available in an hour or so.

 

 






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





What email should I send it to?

@rachaelwalker not sure if it last message is for me, you can share it by onedrive/google drive link or send it directly, my email is in the signature.






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





@parry2k I sent you a link to your email

@parry2k Thank you for taking the time to resolve this issue. Thankful it was an easy fix and appreciate everyone taking the time.

 

Resolution: Date field in the iauditor table was not set to "Date" data type. 

Hi @rachaelwalker ,

 

You can upload your sample to OneDrive For Business and share the link here.

Please don't contain any Confidential Information or Real data in your reply.

 

Best regards,

 

Community Support Team _ zhenbw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

rachaelwalker
Resolver II
Resolver II

2020-08-03 09_02_04-Technology Dashboard - Power BI Desktop.png

 

Not sure why my screenshots disappeared from original post but here is to show relationship

@rachaelwalker , Hope this can help

Any of the 7 days as week start or end

https://community.powerbi.com/t5/Community-Blog/Any-Weekday-Week-Decoding-Date-and-Calendar-2-5-Powe...

 

My assumption is having date table



Power BI Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!
Want To Learn Power BI | Beginners !! Advance Concepts !! Power BI For Tableau User !!

Super helpful article! I was able to add a column to my date table to show Monday as the week start date. It's the visuals/relationship between the tables that is giving me issues. 

Helpful resources

Announcements
August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors