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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
rachaelwalker
Resolver III
Resolver III

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? 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


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.  



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


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.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


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.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


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.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


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 III
Resolver III

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

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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